關於nginx的多站設置,其實和apache很類似噠。 php
假設咱們已經有兩個域名,分別是:www.websuitA.com和www.websuitB.com。而且這兩個域名已經映射給了IP爲192.168.1.1的服務器。 html
一、爲咱們的站點建立配置文件 nginx
我是這麼作的,在nginx的配置文件conf目錄下建立一個專門存放VirtualHost的目錄,命名爲vhosts_conf,能夠把虛擬目錄的配置所有放在這裏。在裏面建立名爲vhosts_modoupi_websuitA.conf的配置文件並打開,咱們在這裏作配置,往裏面寫: web
server { apache listen 80; #監聽的端口號 瀏覽器 server_name websuitA.com; #域名 服務器 #access_log logs/host.access.log main; 測試 location / { ui root X:/wnmp/www/websuitA; #站點的路徑 spa index default.php index.php index.html index.htm; #站點的rewrite在這裏寫 rewrite ^/(\w+)\.html$ /$1.php; rewrite ^/(\w+)/(\w+)$ /$1/$2.php; } #錯誤頁的配置 error_page 404 /error.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root X:/wnmp/www/websuitA; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } |
這樣就作好了,站點A的配置,一樣的方法,作websuitB的配置,這裏我命名爲vhosts_modoupi_websuitB.conf
server { listen 80; #監聽的端口號 server_name websuitB.com; #域名 #access_log logs/host.access.log main; location / { root X:/wnmp/www/websuitB; #站點的路徑 index default.php index.php index.html index.htm; #站點的rewrite在這裏寫 rewrite ^/(\w+)\.html$ /$1.php; rewrite ^/(\w+)/(\w+)$ /$1/$2.php; } #錯誤頁的配置 error_page 404 /error.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root X:/wnmp/www/websuitB; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } |
這樣,兩個站點的配置就OK了。
二、在nginx的主配置文件裏,包含這兩個站點的配置文件。
咱們打開conf目錄下的nginx.conf文件,很容易作,只要在http{...}段輸入如下代碼:
#包含全部的虛擬主機的配置文件 include X:/wnmp/nginx/conf/vhosts_conf/*.conf; |
這樣,nginx的多站點配置就作好了,怎麼樣打開瀏覽器測試一下吧~