nginx로 로드 밸런싱을 수행하는 방법

nginx로 로드 밸런싱을 수행하는 방법

서버를 로드 밸런서와 웹 서버로 동시에 사용해야 합니다.

웹사이트에 대한 내 nginx 구성은 다음과 같습니다.

upstream load_balancer {
    least_conn;
    server localhost;
        #server srv2.example.com;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name localhost;

    root /var/www;

    index index.php index.html index.htm;

    location / {
        proxy_pass http://load_balancer;
    }

    location ~* \.php$ {
        fastcgi_index   index.php;
            fastcgi_pass    unix:/var/run/php5-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

하나의 서버를 로드밸런서와 웹서버로 동시에 사용할 수 있나요? 어떻게 하나요?

미리 감사드립니다!

답변1

예, 가능합니다.

다른 포트를 사용하여 가상 호스트를 만들 수 있습니다.

(Load Balancer [Port 80] + Virtualhost [Port 81])따라서 사실상 두 개의 포트를 수신하는 하나의 서버가 있게 됩니다. 하나는 웹페이지를 제공하고 다른 하나는 로드 밸런싱을 제공합니다.

그런 다음 서버의 웹사이트를 로드 밸런서에 연결할 때 IP를 사용합니다.localhost:81

다음을 입력하여 로컬 웹사이트를 생성할 수 있습니다.

sudo nano /etc/nginx/sites-available/example.com

그런 다음 붙여넣습니다(필요에 따라 편집해야 할 수도 있습니다.)

 server {
        listen   81;

        root /var/www/example.com/public_html;
        index index.html index.htm;

        server_name example.com;
}

도움이 되었기를 바랍니다!

관련 정보