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

在GitHub Actions中配置Nginx站点时出现启动失败问题

解决Nginx在GitHub Actions中启动失败的问题

核心原因

GitHub Actions的运行虚拟机里没有local.everestate.de和local.everestate.com的DNS解析记录。你本地能正常运行,是因为本地/etc/hosts文件里已经把这些域名映射到了对应IP(比如127.0.0.1),但CI环境默认没有这个配置,导致Nginx启动时无法找到上游服务器,触发host not found in upstream错误。

解决办法

方法1:给CI环境添加hosts映射

在修改Nginx配置的步骤前后,添加一个步骤把这两个域名写入/etc/hosts,指向127.0.0.1(假设你要代理的服务运行在CI环境本地):

- name: Add local domains to system hosts
  run: |
    echo "127.0.0.1 local.everestate.de" | sudo tee -a /etc/hosts
    echo "127.0.0.1 local.everestate.com" | sudo tee -a /etc/hosts

方法2:直接替换Nginx配置中的上游地址

如果不需要保留域名测试,或者上游服务本身就运行在本地端口,可以把proxy_pass里的域名换成127.0.0.1(记得加上服务的端口号,比如127.0.0.1:8080):

proxy_pass http://127.0.0.1;  # 或带端口的http://127.0.0.1:xxxx

如果必须保留域名,也可以给proxy_pass配置DNS resolver,但这种方式不如修改hosts直接:

location / {
    resolver 8.8.8.8 valid=30s;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://local.everestate.de;
}

额外调试建议

在启动Nginx前先测试配置文件,提前发现问题:

- name: Validate NGINX configuration
  run: sudo nginx -t

把这个步骤放在Update NGINX configuration之后、Start NGINX之前,能快速验证配置是否合法。

修改后的完整工作流示例

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: Install Nginx
    run: |
      sudo apt-get update
      sudo apt-get install -y nginx

  - name: Add local domains to system hosts
    run: |
      echo "127.0.0.1 local.everestate.de" | sudo tee -a /etc/hosts
      echo "127.0.0.1 local.everestate.com" | sudo tee -a /etc/hosts

  - name: Update NGINX configuration
    run: |
      echo "
      server {
          listen 80;
          server_name local.everestate.de;

          location / {
              proxy_set_header X-Forwarded-For \$remote_addr;
              proxy_set_header Host \$http_host;
              proxy_pass http://local.everestate.de;
          }
      }

      server {
          listen 80;
          server_name local.everestate.com;

          location / {
              proxy_set_header X-Forwarded-For \$remote_addr;
              proxy_set_header Host \$http_host;
              proxy_pass http://local.everestate.com;
          }
      }" | sudo tee -a /etc/nginx/sites-available/default > /dev/null

  - name: Validate NGINX configuration
    run: sudo nginx -t

  - name: Log configuration details
    run: |
      cat /etc/hosts
      cat /etc/nginx/sites-available/default

  - name: Start NGINX
    run: |
      sudo systemctl start nginx
      sudo systemctl status nginx.service

内容的提问来源于stack exchange,提问作者Patryk Karpiński

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 23:54:51