Nginx PHPマルチサイト構成

7837 ワード

Nginx PHPマルチサイト構成
2つのサイト(2つのドメイン名)を構成する場合、nつのサイトが調整を追加できると仮定します.
IPアドレス:202.55.1.100ドメイン名1 example 1.comは/www/example 1ドメイン名2 example 2に置く.comは/www/example 2に置く
nginx virtual hostingを構成する基本的な考え方と手順は以下の通りである:2つのサイトexample 1.com, example2.comはnginxがアクセスできるディレクトリ/www/各サイトにnginxプロファイルexample 1をそれぞれ作成する.com.conf,example2.com.confは、/etc/nginx/vhosts/にプロファイルを配置し、/etc/nginx.confにincludeを付けて手順2で作成したプロファイルをすべて含めてnginxを再起動します
具体的なプロセスは次のとおりです.
1、/etc/nginxでvhostsディレクトリを作成する
mkdir /etc/nginx/vhosts

2、/etc/nginx/vhosts/にexample 1という名前を作成する.com.confのファイルは、以下の内容をコピーします.
server {
        listen  80;
        server_name  example1.com www. example1.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root  /www/example1.com;
            index  index.php index.html index.htm;
        }

        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root  /usr/share/nginx/html;
        }

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ /.php$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/example1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

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

3、/etc/nginx/vhosts/にexample 2という名前を作成する.com.confのファイルは、以下の内容をコピーします.
server {
        listen  80;
        server_name  example2.com www. example2.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root  /www/example2.com;
            index  index.php index.html index.htm;
        }

        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root  /usr/share/nginx/html;
        }

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ /.php$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/example2.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

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

4、/etc/nginixを開く.confファイル、該当する場所にincludeを入れて以上の2つのファイルを含みます
user  nginx;
worker_processes  1;

# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;

events {
 worker_connections  1024;
}
# main server config
http {
 include       mime.types;
 default_type  application/octet-stream;
 log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 sendfile        on;
 #tcp_nopush     on;
     #keepalive_timeout  0;
 keepalive_timeout  65;
 gzip  on;

 server {
         listen         80;
         server_name     _;
         access_log      /var/log/nginx/access.log main;
         server_name_in_redirect  off;
         location / {
              root  /usr/share/nginx/html;
              index index.html;
         }
 }

    #               
    include /etc/nginx/vhosts/*;
}

5、Nginxを再起動する
/etc/init.d/nginx restart

転載先:http://blog.csdn.net/ouyangzhan/article/details/6015243#comments