我是nginx的新手,我试图让我的second.domain.com显示first.domain.com/dir的内容,(在我的localhost的端口3000上运行)在线似乎这是解决方案
# this one works fine
server {
listen 80;
server_name first.domain.com;
location / {
proxy_pass http://localhost:3000;
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;
}
}
# this one doesn't work as expected
server {
listen 80;
server_name second.domain.com;
location / {
proxy_pass http://localhost:3000;
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;
root /dir;
index index.html;
}
}
但是当我访问second.domain.com时,我获得与first.domain.com相同的root而不是first.domain.com/dir ...任何人都可以看到我做错了什么?
答案 0 :(得分:1)
对mim的评论嗤之以鼻,我让它以这种方式工作
# this one is now working as planned :)
server {
listen 80;
server_name second.domain.com;
location / {
# added mim's suggestiong here
rewrite /folder/(.*) /$1 break;
# then added the folder after the port
proxy_pass http://localhost:3000/folder;
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;
root /dir;
index index.html;
}
}