【发布时间】:2021-12-16 07:26:59
【问题描述】:
好的,我的 Ubuntu VPS 有一个不寻常的问题。访问一个域显示另一个域的静态 html 页面。让我们看一下congif。
假设我有一个域:site1.com。该域有 2 个应用程序在子域中完美运行:app1.site1.com 和 app2.site1.com。主页没有任何应用程序,只有一个简单的 html 页面,上面写着:
'Welcome to Site 1. This site is currently under maintenance!'.
这是我想要的完美运行,但是在我从 Namecheap 指向我的 VPS 的一个新域(我们称他为 site2.com)之后,问题就出现了。现在当我访问 site2.com 时,我可以看到:
'Welcome to Site 1. This site is currently under maintenance!'.
这就是真正的巫毒魔法。
site1 nginx 配置文件如下所示:
server {
root /var/www/html/site1.com;
index index.html index.htm index.nginx-debian.html;
server_name site1.com www.site1.com;
location / {
try_files $uri $uri/ =404;
}
}
server {
root /var/www/app1.site1.com;
index index.html index.htm index.nginx-debian.html;
server_name app1.site1.com;
location / {
#try_files $uri $uri/ =404;
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
server {
root /var/www/app2.site1.com;
index index.html index.htm index.nginx-debian.html;
server_name app2.site1.com;
location / {
#try_files $uri $uri/ =404;
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
html文件在/var/www/html/site1.com/index.html
魔法的原因是什么?
我也尝试过为新域创建一个新的 nginx 文件并创建一个新的服务器块并指向它自己的 html 文件,但它只是不显示该 html 页面,而是显示 site1 页面。
如果有人指出我正确的方向,那将非常有帮助。
【问题讨论】:
标签: ubuntu nginx nginx-reverse-proxy nginx-config ubuntu-20.04