FreeBsd Nginx Virtual Hosting 구성

가정 1.

도매인 : vhost_host_1.com, vhost_host_2.com 으로 구성한다는 가정.

# mkdir -p /var/www/vhost_host_1.com

# mkdir -p /var/www/vhost_host_2.com

# echo "vhost_host_1.com" > /var/www/vhost_host_1.com/index.php

# echo "vhost_host_2.com" > /var/www/vhost_host_2.com/index.php

# vi /usr/local/etc/nginx/nginx.conf

http {
   …
   include sites-enabled/*;
}

http 블록 안에 include sites-enabled/*; 내용 추가

# mkdir -p /usr/local/etc/nginx/sites-enabled

# cp /usr/local/etc/nginx/nginx.conf-dist /usr/local/etc/nginx/sites-enabled/vhost_host_1.com.conf

# cp /usr/local/etc/nginx/nginx.conf-dist /usr/local/etc/nginx/sites-enabled/vhost_host_2.com.conf

# vi /usr/local/etc/nginx/sites-enabled/vhost_host_1.com.conf

    server {
        listen       80;
        server_name  vhost_host_1.com;

        root   /var/www/vhost_host_1.com;
        index  index.php;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

    	location ~ \.php$ {

             try_files $uri /index.php =404;
             fastcgi_split_path_info ^(.+\.php)(/.+)$;
             fastcgi_pass unix:/var/run/php-fpm.sock;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME 
             $document_root$fastcgi_script_name;
             include fastcgi_params;
        }

        location ~ /\.ht {
            deny  all;
        }
    }

# vi /usr/local/etc/nginx/sites-enabled/vhost_host_2.com.conf

    server {
        listen       80;
        server_name  vhost_host_2.com;

        root   /var/www/vhost_host_2.com;
        index  index.php;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

    	location ~ \.php$ {

             try_files $uri /index.php =404;
             fastcgi_split_path_info ^(.+\.php)(/.+)$;
             fastcgi_pass unix:/var/run/php-fpm.sock;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME 
             $document_root$fastcgi_script_name;
             include fastcgi_params;
        }

        location ~ /\.ht {
            deny  all;
        }
    }

# nginx -c /usr/local/etc/nginx/nginx.conf -t

# service nginx restart

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다