Nginxは複数の仮想ホストを構成し、includeを利用してコード量を低減する方式である.

6483 ワード

仮想ホストの構成は、一つのserverが一つの仮想ホストを表しています.ここでは重複して設定できる配置が多く、includeを使用して、複数のホストを設定する時、プロファイルのコード量を減らすことができます.設定ファイルvim/usr/local/nginx/conf/nginx.com nfを修正してhttpを見つけます.server{listen 80 default userver;上に以下のコードを挿入します.
include/usr/local/nginx/conf.d/*.conf
cd/usr/local/nginx/conf.d/ディレクトリ作成ファイルvim local host.co nfに入ります.
内容は以下の通りです
server {
        listen       3700;
        server_name  localhost;
        error_log /var/log/nginx/localhost-error.log;#        
        rewrite_log on; #         
        #access_log  logs/host.access.log  main;
        root   /data/web/localhost-api/web;//        
        location /static/ {
            root /data/web/localhost-api/;
        }   
#       location ~\.jpg|\.png|\.jpeg|\.gif|\.js|\.html|\.css$ {
#           root /data/web/localhost-api/static;
#       }
        location /uploaded/ {
            root /data/web/localhost-api/;
        }   

        location / { 
            index  index.php index.html index.htm;
            if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
                #rewrite /index.html /index last;
            }
        }
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           /data/web/localhost-api/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  LOCAL_ENV          "localhost";//      
            include        fastcgi_params;
        }

    }