同一個nginx配置文件,請求不同的域名可以指定對應的目錄
- nginx配置
cat long.conf
server {
listen 80;
server_name a.com b.com c.com;
location / {
root /home/long/$host/;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 創建對應的目錄
cd /home/long
mkdir a.com b.com c.com
#對應目錄下創建index.html文件
echo 'test a.com' a.com/index.html
...
- 訪問測試
本地測試,需將nginx所在的ip和域名加入到hosts里