You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx多端口绑定多域名异常:Docker应用域名访问问题

Troubleshooting App_2 Domain Access Issue with Nginx & Docker

Hey there! Since your App_1 is working perfectly with its domain, we can focus on a few key areas that are likely causing the problem with App_2. Let's walk through the most common fixes step by step:

1. Verify Your Nginx Server Block for App_2

First, double-check your Nginx configuration file for App_2's server block. It's easy to miss a small detail here that breaks everything.

Your config should look something like this (adjust paths/IPs as needed):

server {
    listen 80;
    server_name app.2.com;  # Make sure this matches your domain exactly

    location / {
        # Point this to your App_2's accessible address (IP:port or Docker container name if on the same network)
        proxy_pass http://192.168.1.x:8081;
        # These headers help your app recognize the original request details
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

After updating the config, test it for syntax errors with:

nginx -t

If it passes, reload Nginx to apply changes:

systemctl reload nginx  # For systemd systems
# Or
service nginx reload    # For older init systems

2. Confirm DNS Resolution for app.2.com

If your domain isn't pointing to the right server IP, you'll get errors even with a perfect Nginx config.

  • On your local machine, run nslookup app.2.com or ping app.2.com to check if it resolves to 192.168.1.x.
  • If this is a local test (not a public domain), add an entry to your hosts file:
    • Linux/macOS: Edit /etc/hosts and add 192.168.1.x app.2.com
    • Windows: Edit C:\Windows\System32\drivers\etc\hosts (as admin) and add the same line

3. Check Firewall/Security Group Rules

Even though you can access App_2 via IP:8081, make sure the port Nginx is listening on (usually 80 for HTTP) is open:

  • On Linux, use ufw status (if using UFW) or firewall-cmd --list-all (if using firewalld) to confirm port 80 is allowed.
  • If you're using a cloud provider, check your security group settings to ensure inbound traffic on port 80 is permitted.

4. Validate Docker Network & Port Mapping

Since IP:8081 works, your port mapping is probably correct, but let's double-check:

  • Run docker ps and look for App_2's port entry. It should show 0.0.0.0:8081->[container-port]/tcp (not 127.0.0.1:8081..., which would only allow local access from the server itself).
  • If your Nginx is also running in Docker, ensure App_2 is connected to the same Docker network as Nginx. You can connect it with:
    docker network connect [nginx-network-name] [app2-container-name]
    
    Then you can update the proxy_pass in Nginx to use the container name (e.g., http://app2-container:8081) instead of the host IP, which is more reliable for Docker setups.

5. Dig Into Nginx Logs

If none of the above fixes work, check Nginx's logs to get specific error details:

  • Error Log: Typically located at /var/log/nginx/error.log — look for entries when you try to access app.2.com (e.g., 502 Bad Gateway means Nginx can't reach App_2, 404 means the proxy path is wrong).
  • Access Log: Located at /var/log/nginx/access.log — check if the requests to app.2.com are even reaching Nginx.

Start with the first two steps (Nginx config and DNS) since those are the most common culprits. Let me know if you hit any specific errors and we can narrow it down further!

内容的提问来源于stack exchange,提问作者Alan Aranda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:13:50