目标:實作多域名通路伺服器
進入到nginx配置檔案,修改nginx.conf配置檔案
在#gzip on;下删除所有内容,删除完成後加入以下内容,這裡隻以a b 兩個網站為例,如果還有c d 等網站部署方法也一樣,隻需按照這種格式複制粘貼就好。
server {
listen 80;
server_name www.a.com;
#access_log logs/host.access.log main;
location / {
root html/a;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.b.com;
#access_log logs/host.access.log main;
location / {
root html/b;
index index.html index.htm;
}
}
}
具體注釋
添加完成後去建立 a b 兩個釋出目錄,需在預設釋出目錄下建立/usr/local/nginx/html
進入a釋出目錄修改網頁内容
[[email protected] html]# cd a
[[email protected] a]# vim index.html
進入b釋出目錄修改網頁内容
[email protected] a]# cd …/
[[email protected] html]# cd b
[[email protected] b]# vim index.html
檢查服務是否能正常啟動
[[email protected] b]# /usr/local/nginx/sbin/nginx -t
啟動服務并檢視80端口是否被監聽到
[[email protected] b]# /usr/local/nginx/sbin/nginx
[[email protected] b]# netstat -nel |grep 80
因為我們域名不是真正的注冊域名,是以隻能在本地電腦etc檔案添加域名解析後才能通路
通路a網頁
通路b網頁
1、a b 釋出目錄需要建立在nginx預設的釋出目錄下面