我有多個本地站點,我想配置nginx以使每個站點都有不同的主機。在nginx中更改localhost主機名
在/ var /萬維網我有2個位點:1和Site2
然後在/ etc/nginx的/位點可用/ I 2個創建不同的配置爲每一個服務器。我有文件1和Site2哪些內容是這樣的:
server {
listen 80;
root /var/www/site1;
index index.html index.htm;
server_name localhost;
location/{
try_files $uri $uri/ /index.html;
}
}
和
server {
listen 7777;
root /var/www/site2;
index index.html index.htm;
server_name localhost;
location/{
try_files $uri $uri/ /index.html;
}
}
我訪問他們http://localhost:80
爲Site1和http://localhost:7777
的站點2。這是完美的。我還可以在/ etc添加主機名/主機這樣的:
127.0.0.1 localhost site1 site2
,我可以用http://site1:80
和http://site2:7777
訪問它們。但我必須始終訪問端口號。我想通過http://site1
和http://site2
訪問它們。
有沒有解決方案來做到這一點?
我通過將server_name更改爲site1和site2,然後放置相同的端口80找到了解決方案。 –