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

无法通过Nginx访问本地子域名images.locaserver.com的问题排查

问题原因及解决办法

核心问题

你的Nginx没有正确匹配images.locaserver.com:8080对应的server块,导致请求被默认转发到了第一个监听8080端口的server(React应用的3000端口)。这通常是因为images.locaserver.com的server块缺少正确的server_name配置,或者配置存在语法疏漏。

解决步骤

1. 检查并修正Nginx的server块配置

打开/opt/homebrew/etc/nginx/nginx.conf,确保三个server块的配置符合以下格式,重点确认server_name和代理规则:

# React应用(locaserver.com:8080 -> 3000)
server {
    listen 8080;
    server_name locaserver.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

# Node.js API(api.locaserver.com:8080 -> 8081)
server {
    listen 8080;
    server_name api.locaserver.com;

    location / {
        proxy_pass http://localhost:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

# 图片服务(images.locaserver.com:8080 -> 8083)
server {
    listen 8080;
    server_name images.locaserver.com;

    location / {
        proxy_pass http://localhost:8083;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

2. 验证Nginx配置正确性

在终端执行命令,检查配置文件是否存在语法错误:

nginx -t

若输出test is successful,说明配置合法;如有错误,根据提示修正对应问题。

3. 重启Nginx服务

配置验证通过后,重启Nginx让新配置生效:

brew services restart nginx

4. 测试访问

此时访问http://images.locaserver.com:8080,应该会正确转发到8083端口的Node应用。

额外排查点

  • 若问题仍存在,检查/etc/hosts文件是否正确映射images.locaserver.com到127.0.0.1,可执行ping images.locaserver.com确认解析结果。
  • 查看Nginx访问日志(路径通常为/opt/homebrew/var/log/nginx/access.log),检查请求的Host头是否为images.locaserver.com,确认请求是否被正确识别。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 11:00:42