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

NGINX虚拟主机反向代理本地服务未生效问题求助

问题排查与解决步骤

1. 验证后端服务是否正常运行

  • 执行命令检查10000端口是否被监听:
    ss -tulpn | grep 10000
    
    确认输出中存在对应服务进程,说明端口处于活跃状态。
  • 直接在本地访问后端服务:
    curl http://127.0.0.1:10000
    
    如果本地访问也无响应,问题出在后端服务本身,需先排查服务启动状态与配置。

2. 确认域名解析配置

如果是本地测试环境,必须将jg1.example映射到本机IP:

  • Linux系统编辑/etc/hosts,Windows系统编辑C:\Windows\System32\drivers\etc\hosts,添加以下内容:
    127.0.0.1 jg1.example
    
    保存后刷新DNS缓存(Linux执行systemctl restart systemd-resolved,Windows执行ipconfig /flushdns)。

3. 检查NGINX代理配置细节

  • 补充必要的代理请求头,修改location /块内容:
    location / {
        proxy_pass http://127.0.0.1:10000/;
        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_connect_timeout 30s;
        proxy_send_timeout 30s;
        proxy_read_timeout 30s;
    }
    
    增加超时配置可避免因后端响应慢导致的无反馈问题。

4. 排查系统防火墙与SELinux限制

  • 检查防火墙是否开放80端口:
    # 以ufw为例
    ufw status
    # 未开放则执行
    ufw allow 80/tcp
    
  • 检查SELinux状态(仅Linux):
    sestatus
    
    若处于enforcing模式,临时关闭测试:
    setenforce 0
    
    测试正常后,永久允许NGINX连接网络:
    setsebool -P httpd_can_network_connect 1
    

5. 启用Debug日志定位问题

修改配置文件中的error_log级别为debug:

error_log /var/log/nginx/jg1error.log debug;

执行nginx -t验证配置语法,再执行systemctl reload nginx重启服务。再次访问后查看jg1error.log,日志会详细记录代理连接的全过程,可精准定位超时、拒绝等问题。

6. 确保NGINX配置生效

每次修改配置后,必须执行:

nginx -t && systemctl reload nginx

确认配置无语法错误且服务已重载。

内容的提问来源于stack exchange,提问作者Jairo Guerra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 09:30:59