2
我仍然在爲一個虛擬機中的多個網站配置nginx而苦苦掙扎。 所以,如果我做的:NGINX在一個VPS實例中的多個網站
server {
listen 80;
server_name example1.com;
location/{
proxy_pass http://localhost:8181;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
命中example1.com後,我的網頁的NodeJS正確裝入。但是,如果我嘗試添加第二個服務器塊:
server {
listen 80;
server_name example2.com;
location/{
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
沒有任何工作,也example1。所以,我想通過example2.com默認nginx的位置加載......類似的東西:
server {
listen 80;
server_name example1.com;
location/{
root /usr/share/nginx/html;
index index.html index.htm;
}
}
server {
listen 80;
server_name example2.com;
location/{
proxy_pass http://localhost:8181;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
但它始終是重定向到nginx的根位置。
我該怎麼做?謝謝你的幫助!