繁体   English   中英

Nginx 502 当 Jenkins 管道正在为 React 应用程序运行 docker 时出现错误网关

[英]Nginx 502 Bad Gateway when Jenkins pipeline is running a docker for React app

我有一个Ubuntu 18.04服务器在使用 SSL 保护并使用Nginx 反向代理的 Droplet(DigitalOcean)中运行。 Jenkins在我的服务器中运行(不在任何 docker 中)并配置为在我为其创建的域下访问:jenkins.testdomain.com(所有这些步骤都遵循 DO 文档)

所以目标是管理Node.js-React 应用程序到我的 testdomain.com 的部署,现在,我只想在 /var/lib/ 中创建在“npm build”之后生成的dist文件夹詹金斯/工作区/,就是这样。

到目前为止,我可以访问我的 jenkins.testdomain.com 站点好了,在推送到我的仓库后触发管道启动进程,并开始运行阶段; 但它开始失败 nginx 时,当管道到达交付阶段(让我们阅读“npm build”阶段)时,有时在构建阶段(“npm install”)。

在这一点上,读取 Jenkins 控制台 output 我看到它何时卡住并最终显示502 Bad Gateway错误。 我需要在我的服务器控制台中运行命令systemctl restart Jenkins才能再次访问。 重新启动后,管道恢复工作,似乎完成了工作:/

nginx的 /var/log/nginx/error.log 中,我可以阅读:

*1 连接到上游时连接()失败(111:连接被拒绝),客户端:85.146.85.194,服务器:jenkins.testdomain.com,请求:“GET /job/Basic%20NodeJS-React%20app/8 /1.1”,上游:“https://127.0.0.1:8080/job/Basic%20NodeJS-React%20app/8/console”,主机:“jenkins.testdomain.com”,引用者:“https://jenkins .testdomain.com/job/Basic%20NodeJS-React%20app/8/"

*1 SSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number) while SSL handshaking to upstream, client: 85.146.85.194, server: jenkins.testdomain.com, request: "GET /favicon.ico HTTP/1.1”,上游:“https://127.0.0.1:8080/favicon.ico”,主机:“jenkins.testdomain.com”,引用者:“https://jenkins.testdomain.com/job/Basic% 20NodeJS-React%20app/8/console"...

在我的 node-js-react 应用程序的 Jenkinsfile 中(来自 jenkins repo ),代理如下所示:

pipeline {
    agent {
        docker {
            image 'node:6-alpine' 
            args '-p 3000:80' 
        }
    }
    environment {
            CI = 'true'
    }
    stages {
            // Build, Test, and Deliver stages
    }
}

And my jenkins.testdomain.com configuration (/etc/nginx/ sites-available/jenkins.testdomain.com ) is like this (pass tests from nginx -t):

server {
    listen 80;

    root /var/www/jenkins.testdomain.com/html;
    server_name jenkins.testdomain.com www.jenkins.testdomain.com;

    location / {
      proxy_set_header    Host $host;
      proxy_set_header    X-Real-IP $remote_addr;
      proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://localhost:8080;

      # High timeout for testing
      proxy_connect_timeout 1200s;
      proxy_send_timeout 1200s;
      proxy_read_timeout 1200s;

      proxy_redirect      http://localhost:8080 https://jenkins.testdomain.com;

      # Required for new HTTP-based CLI
      proxy_http_version 1.1;
      proxy_request_buffering off;

      # Required for HTTP-based CLI to work over SSL
      proxy_buffering off;
    }

    # Certbot auto-generated lines...
}

任何帮助都将受到非常欢迎 3 天努力解决这个问题并使用 nginx 的不同 proxy_ 指令等等......提前致谢!

好吧,在我最新发布的几天后添加一个更新,我意识到服务器出现故障的主要原因和唯一原因是 droplet 中缺乏资源。

所以我使用了一个具有 1GB RAM、25GB HD 等(最基本的)的液滴,所以我选择更新它以使用至少 2GB 的 RAM,事实上,这使它按我的预期工作。 到目前为止一切正常,并且该问题没有再次发生。

如果有人遇到同样的问题,希望它会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM