1. 程式人生 > >nginx下的站點配置(埠和hosts)兩種模式

nginx下的站點配置(埠和hosts)兩種模式

一般預設是80埠,以hosts模式配置多站點可以設定如下:

server {
     listen       80;
     server_name   allwood-com.cn;
     root   "D:/phpStudy/WWW/allwood-com";
     charset     utf-8;
     index       index.php index.html index.htm;
     

    location / {
        index  index.html index.htm index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }


    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         fastcgi_param  APP_ENV  'test';


        #fastcgi_param PATH_INFO $request_uri;


    }
}


server {
    listen       80;
    server_name   tp_wood.cn;
     root   "D:/phpStudy/WWW/tp_wood";
    charset     utf-8;
    index       index.php index.html index.htm;
   try_files   $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /index.php?s=/$1;
    }


    location ~ \.php$ {
         root   "D:/phpStudy/WWW/tp_wood";
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        include        fastcgi_params;
         client_max_body_size 5m;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}

這是兩個nginx兩個配置,對應的hostst配置就如下:

127.0.0.1 allwood-com.cn
127.0.0.1 tp_wood.cn

這樣就完成了兩個站點的配置了。如果不想配置hosts,可以配置埠;

server {
        listen       8090;
        server_name  www.ykg.com ykg.cn;
        root   "D:/phpStudy/WWW/ykg/public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
   autoindex off;
                                           if (!-e $request_filename) {
                                                  rewrite ^(.*)$ /index.php?s=$1 last;
                                                  break;
                                           }
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
server {
        listen       8080;
        server_name  www.testredis.com testredis.cn;
        root   "D:/phpStudy/WWW/laravel/public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
   autoindex off;
                                           if (!-e $request_filename) {
                                                  rewrite ^(.*)$ /index.php?s=$1 last;
                                                  break;
                                           }
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

這樣的配置也是ok的。