我的 Nginx 反向代理出现了一些非常奇怪的问题。特别是一个域名无法正确解析,而是显示完全不同的主机的站点。只有wiki.example.net是错误的,它会重定向到www.client.co.uk一切都很好。
在 /etc/nginx/sites-available 中的 3 个独立文件中
默认
server {
listen 80 default_server;
server_name _;
root /var/www/example/;
index index.html index.php;
include /etc/nginx/include/php;
}
wiki.example.net
upstream examplewiki {
server 10.2.7.18:80;
}
server {
listen 80;
server_name wiki.example.net;
location / {
proxy_pass http://examplewiki/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
www.client.co.uk
upstream client {
server 10.2.7.12:80;
}
server {
server_name .client.co.uk;
return 301 http://www.client.co.uk$request_uri;
}
server {
server_name .client.com;
return 301 http://www.client.co.uk$request_uri;
}
server {
listen 80;
server_name www.client.co.uk;
location / {
proxy_pass http://client/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
只为wiki.example.netURL 被重写为www.client.co.uk和www.client.co.uk页面显示。其他一切都正常。我还有其他后端 VPS 和其他类似的配置文件,它们也都正常。