nginx伺服器下配置多個站點的方法

2021-06-27 07:09:33 字數 1461 閱讀 5187

這裡以配置2個站點(2個網域名稱)為例,n 個站點可以相應增加調整,假設:

配置 nginx virtual hosting 的基本思路和步驟如下:

把2個站點 example1.com, example2.com 放到 nginx 可以訪問的目錄 /www/

給每個站點分別建立乙個 nginx 配置檔案 example1.com.conf,example2.com.conf, 並把配置檔案放到 /etc/nginx/vhosts/

然後在 /etc/nginx.conf 裡面加一句 include 把步驟2建立的配置檔案全部包含進來(用 * 號)

重啟 nginx

下面是具體的配置過程:

1、在 /etc/nginx 下建立 vhosts 目錄

mkdir /etc/nginx/vhosts
2、在 /etc/nginx/vhosts/ 裡建立乙個名字為 example1.com.conf 的檔案,把以下內容拷進去

server 

error_page 500 502 503 504 /50x.html;

location = /50x.html

# pass the php scripts to fastcgi server listening on 127.0.0.1:9000

location ~ \.php$

location ~ /\.ht

}

3、在 /etc/nginx/vhosts/ 裡建立乙個名字為 example2.com.conf 的檔案,把以下內容拷進去

server 

error_page 500 502 503 504 /50x.html;

location = /50x.html

# pass the php scripts to fastcgi server listening on 127.0.0.1:9000

location ~ \.php$

location ~ /\.ht

}

4、開啟 /etc/nginix.conf 檔案,在相應位置加入 include 把以上2個檔案包含進來

} # 包含所有的虛擬主機的配置檔案

include /usr/local/etc/nginx/vhosts/*;

}5、重啟 nginx

/etc/init.d/nginx restart

在Nginx伺服器中設定多個站點

當我們有了乙個 vps 主機以後,為了不浪費 vps 的強大資源 相比共享主機1000多個站點擠在一台機器上 往往有想讓 vps 做點什麼的想法,銀子不能白花啊 放置多個 或者部落格是個不錯的想法,可是如何配置 web 伺服器才能在乙個 vps 上放置多個 部落格呢?如何通過乙個 ip 訪問多個站點...

nginx配置http靜態站點伺服器

1 系統環境windows 10 2 設定靜態站點目錄,注意不要出現中文 這裡踩了很多坑,可以檢視錯誤日誌error.log,這裡測試了一下目錄 3 配置nginx.conf server location download error page 404 404page index.html 監聽埠...

windows下配置nginx伺服器

c server nginx start nginxc server nginx nginx.exe 強制停止 c server nginx nginx.exe s stop 儲存並停止 c server nginx nginx.exe s quit c server nginx nginx.exe...