nginxのバーチャルホストの設定仮想ホストサポートPHP +

説明:サーバー設定のIPアドレスへの最初のドメイン名解決さの前に

サイト1:bbs.osyunwei.comプログラムディレクトリ/データ/ osyunwei / BBS

サイト2:sns.osyunwei.comプログラムディレクトリ/データ/ osyunwei / SNS

chownコマンドwww.www /データ/ osyunwei / -R#ディレクトリ提供の所有者、WWWのアカウントが実行されているnginxの

chmodの700 /データ/ osyunwei / -R#セットディレクトリのパーミッション

nginxの設定ファイルのパス:/usr/local/nginx/conf/nginx.conf

あなたは元の設定ファイルのcp /usr/local/nginx/conf/nginx.confの/usr/local/nginx/conf/nginx.confbakをバックアップ変更する前に

空のホストヘッダーのnginxのI.禁止

VI /usr/local/nginx/conf/nginx.conf#編集

一番上の行に、以下を追加し、サーバーを検索します。

##############################

サーバー{80デフォルトを聞きます。

               server_name  _;      

               location / {     

                   root   html;      

                   return 404;                     

               }     

               location ~ /.ht {     

                   deny  all;                    

                }      

}

##############################

このセットの後、空のホストヘッダーの訪問はnginx404エラーページに直接ジャンプします。

第二には、インクルードファイルをnginxのウェブホスティングを追加します

CDは/ usr / local / nginxの/ confに/#インストールディレクトリnginxのを入力します

MKDIRバーチャルホスト#仮想ディレクトリを確立

VI /usr/local/nginx/conf/nginx.conf#編集

前のステップを追加するコードを検索し、最後に以下を追加します。

。バーチャルホスト/ * confに含ま;

例えば:

サーバー{80デフォルトを聞きます。

               server_name  _;      

               location / {     

                   root   html;      

                   return 404;                     

               }     

               location ~ /.ht {     

                   deny  all;                    

                }      

}

。バーチャルホスト/ * confに含ま;

##############################

第三に、UNIXドメインソケットの修正コネクタnginxのFastCGIの方法

タッチ/tmp/php-cgi.sock位のphp-cgi.sockファイルを確立します

chownコマンドwww.www /tmp/php-cgi.sock#(ユーザーがnginxのと一致していなければならない)、ファイルの所有者を設定し、WWWであります

VI /usr/local/nginx/conf/nginx.conf#編集nginxの設定ファイル

fastcgi_pass 127.0.0.1:9000;変更

fastcgi_pass UNIX:/tmp/php-cgi.sock。

設定ファイルVI /usr/local/php5/etc/php-fpm.conf#PHP-FPM編集

= 127.0.0.1:9000を聞くように変更

=を/ tmp /のphp-cgi.sock聞きます。

四、改正後/usr/local/nginx/conf/nginx.confプロファイルとしても(編集したファイルの推奨直接使用)

WWW WWWユーザー。

2 worker_processes;

#error_logログ/ error.logに。

#error_logログ/ error.logに予告。

#error_logログ/ error.logに情報;

#pidログ/ nginx.pid。

イベント{

use epoll;

worker_connections  65535;

}

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"';

#access_log  logs/access.log  main;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 300m;

sendfile        on;

tcp_nopush     on;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

#keepalive_timeout  0;

keepalive_timeout  60;

tcp_nodelay on;

server_tokens off;

gzip  on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

サーバー{

 listen       80 default;

 server_name  _;

 location / {

 root   html;

 return 404;

                }

 location ~ /.ht {

 deny  all;

                  }

   }

サーバ

    {

 listen       80;

 #server_name localhost;

 index index.php default.php index.html index.htm default.html default.htm ;

 root /data/osyunwei;

場所〜*。。(PHP | PHP5)$?

                    {

                            fastcgi_pass  unix:/tmp/php-cgi.sock;

                            fastcgi_index index.php;

                            include fcgi.conf;

                    }

            location /status {

                    stub_status on;

                    access_log   off;

            }

            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

                    {

                            expires      30d;

                    }

            location ~ .*\.(js|css)?$

                    {

                            expires      12h;

                    }

            access_log off;

    }

。バーチャルホスト/ * confに含ま;

}

第五には、設定ファイルを作成fcgi.conf

VI /usr/local/nginx/conf/fcgi.conf#以下を追加します

fastcgi_param GATEWAY_INTERFACE CGI / 1.1;

fastcgi_param SERVER_SOFTWARE nginxの/ $ nginx_version。

fastcgi_param QUERY_STRING $ QUERY_STRING。

fastcgi_param REQUEST_METHOD $ REQUEST_METHOD。

fastcgi_param CONTENT_TYPE $ CONTENT_TYPE。

fastcgi_param CONTENT_LENGTH $ CONTENT_LENGTH。

fastcgi_param SCRIPT_FILENAME $ DOCUMENT_ROOT $ fastcgi_script_name。

fastcgi_param SCRIPT_NAME $ fastcgi_script_name。

fastcgi_param REQUEST_URI $ REQUEST_URI。

fastcgi_param DOCUMENT_URI $ DOCUMENT_URI。

fastcgi_param DOCUMENT_ROOT $ DOCUMENT_ROOT。

fastcgi_param SERVER_PROTOCOLする$ SERVER_PROTOCOL。

fastcgi_param REMOTE_ADDR $ REMOTE_ADDR。

fastcgi_param REMOTE_PORT $ REMOTE_PORT。

fastcgi_param SERVER_ADDR $ SERVER_ADDR。

fastcgi_param SERVER_PORTの$ SERVER_PORT。

fastcgi_param SERVER_NAMEする$ SERVER_NAME。

PHPが--enable-力のcgi-リダイレクトで構築された場合、PHPは、必要

fastcgi_param REDIRECT_STATUS 200;

第六には、仮想ホストの設定ファイルを作成します

VI /usr/local/nginx/conf/vhost/bbs.osyunwei.com.conf#以下のメモリを追加します

サーバ

    {

            listen       80;

            server_name sns.osyunwei.com;

            index index.php index.html index.htm default.html default.htm default.php;

            root  /data/osyunwei/sns;

場所〜*。。(PHP | PHP5)$?

                    {

                            fastcgi_pass  unix:/tmp/php-cgi.sock;

                            fastcgi_index index.php;

                            include fcgi.conf;

                    }

            location /status {

                    stub_status on;

                    access_log   off;

            }

            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

                    {

                            expires      30d;

                    }

            location ~ .*\.(js|css)?$

                    {

                            expires      12h;

                    }

            access_log off;

    }

セブンテスト

init.dディレクトリ/ PHP-CGI検索

修改:
#DAEMON_OPTS =」 - 127.0.0.1 -p 9000 -C 1 -u WWWデータ-fの/ usr / binに/ PHP-CGI」

DAEMON_OPTS =」 - 127.0.0.1 -s /tmp/php-cgi.sock -C 1 -u WWWデータ-fの/ usr / binに/ PHP-CGI」

VI /data/osyunwei/bbs/index.php#新しいファイルには、追加次の<PHPのphpinfo();?>:保存して終了WQ#!

VI /data/osyunwei/sns/index.php#新しいファイルには、追加次の<PHPのphpinfo();?>:保存して終了WQ#!

/etc/rc.d/init.d/nginx再起動#再起動nginxの

/etc/rc.d/init.d/php-fpm再起動#再起動のphp-FPM

著者:1198553937クルーザー

おすすめ

転載: blog.51cto.com/14624160/2454589