【发布时间】:2015-10-15 13:06:44
【问题描述】:
我仍在为一台虚拟机中的多个网站配置 nginx 而苦苦挣扎。 所以如果我这样做:
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 根位置。
我该怎么做?感谢您的帮助!
【问题讨论】:
标签: node.js nginx reverse-proxy