大网数据广告活动
服务器运维问答

nginx, multiple domains, one server: reachable from some clients, 404 from others

· 52CE 我爱测

I'm trying to host a friend's site on my Ubuntu 16.04 VPS. I myself have multiple sites up at sub1.mydomain.com, sub2.mydomain.com etc. These are nodejs apps, each of them has a proxy-pass setup in an individual file like so: ser…

问题原文

原帖链接 · spinalwrap · CC BY-SA 4.0

I'm trying to host a friend's site on my Ubuntu 16.04 VPS.

I myself have multiple sites up at sub1.mydomain.com, sub2.mydomain.com etc. These are nodejs apps, each of them has a proxy-pass setup in an individual file like so:

server
{
    server_name sub1.mydomain.com;

    location /
    {
        proxy_pass http://localhost:APP_PORT;
        include /etc/nginx/proxy_params;
    }
}

the proxy_params file contains a bunch of stuff which I simply copied from some tutorial:

proxy_buffers 16 32k;
proxy_buffer_size 64k;
proxy_busy_buffers_size 128k;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_connect_timeout 59s;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_ignore_headers Cache-Control Expires;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_no_cache $http_pragma $http_authorization;
proxy_pass_header Set-Cookie;
proxy_read_timeout 600;
proxy_redirect off;
proxy_send_timeout 600;
proxy_temp_file_write_size 64k;
proxy_set_header Accept-Encoding '';
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header Proxy '';
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Original-Request $request_uri;

This has worked for me.

Now I'm trying to point my friend's domain (her-domain.com) to another node app on my server for hosting her site.

server
{
    server_name her-domain.com;

    location /
    {
        proxy_pass http://localhost:HER_APP_PORT;
        include /etc/nginx/proxy_params;
    }
}

funnily, this does not seem to work right. If I use google DNS (8.8.8.8) on my computer, I can reach the app reverse-proxied to that domain just fine and look at the site it serves in my browser. But if I use a default DNS, nginx will serve a 404 page.

Since I can reach the server through that domain and nginx serves that 404, I assume it is an nginx config issue. I'm new to this stuff and don't know how to debug this.

已采纳解答

原帖链接 · spinalwrap · CC BY-SA 4.0

This had nothing to do with DNS.

The issue was that the nginx config did not handle IPv6 requests properly. changing the config to

server
{
    server_name her-domain.com;
    listen 80;
    listen [::]:80;

    location /
    {
        proxy_pass http://localhost:APP_PORT;
        include /etc/nginx/proxy_params;
    }
}

fixed things.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。