国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

nginx 多站點配置方法集合

2024-08-30 12:23:53
字體:
來源:轉載
供稿:網友
那么我們開始吧:
1、為我們的站點創建配置文件
  我是這么做的,在nginx的配置文件conf目錄下創建一個專門存放VirtualHost的目錄,命名為vhosts_conf,可以把虛擬目錄的配置全部放在這里。在里面創建名為vhosts_modoupi_websuitA.conf的配置文件并打開,我們在這里做配置,往里面寫:
復制代碼 代碼如下:
server {
listen 80;               #監聽的端口號
server_name websuitA.com;        #域名
#access_log logs/host.access.log main;
location / {
root X:/wnmp/www/websuitA;    #站點的路徑
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了。
2、在nginx的主配置文件里,包含這兩個站點的配置文件。
  我們打開conf目錄下的nginx.conf文件,很容易做,只要在http{...}段輸入以下代碼:
復制代碼 代碼如下:
#包含所有的虛擬主機的配置文件
include X:/wnmp/nginx/conf/vhosts_conf/*.conf;

這樣,nginx的多站點配置就做好了,怎么樣打開瀏覽器測試一下吧~

第二種方法:
當我們有了一個 VPS 主機以后,為了不浪費 VPS 的強大資源(相比共享主機1000多個站點擠在一臺機器上),往往有想讓 VPS 做點什么的想法,銀子不能白花啊:)。放置多個網站或者博客是個不錯的想法,可是如何配置 web 服務器才能在一個 VPS 上放置多個網站/博客呢?如何通過一個 IP 訪問多個站點/域名呢?這就是大多數 web 服務器支持的 virtual hosting 功能。這里將描述如何一步一步如何用 nginx 配置 virtual hosting。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南靖县| 兴安盟| 大石桥市| 嘉兴市| 四会市| 喀喇沁旗| 高青县| 二连浩特市| 德化县| 页游| 呼伦贝尔市| 芜湖县| 甘泉县| 奉新县| 广平县| 馆陶县| 信阳市| 石门县| 财经| 永寿县| 滦平县| 沁水县| 铜梁县| 罗江县| 綦江县| 双辽市| 岚皋县| 荆门市| 安国市| 高台县| 沙雅县| 双城市| 株洲市| 土默特右旗| 安阳市| 峨山| 平定县| 宣汉县| 平湖市| 肥东县| 新和县|