【问题标题】:502 Bad Gateway for Jenkins with nginx502 带有 nginx 的 Jenkins 的错误网关
【发布时间】:2019-12-04 20:53:49
【问题描述】:

我有一个带有 nginx 的 VPS。 gitlab,phpmyadmin 已经在运行 certbots https。现在我想添加詹金斯。我将其端口更改为 8090,因为它不与 gitlabs 8080 端口合并。我检查了每个状态,所有服务都在运行。

    upstream jenkins {
  keepalive 32;
  server localhost:8090 fail_timeout=0;
}

server {
    server_name build.example.de;

    listen 443 ssl; # managed by Certbot

    access_log  /var/log/nginx/jenkins_access.log;
    error_log   /var/log/nginx/jenkins_error.log;

    ssl_certificate /etc/letsencrypt/live/build.example.de/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/build.example.de/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
     proxy_set_header Host $host:$server_port;
     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;
     proxy_redirect http:// https://;
     proxy_pass http://jenkins;

     # Required for new HTTP-based CLI
     proxy_http_version 1.1;
     proxy_request_buffering off;
     proxy_buffering off; # Required for HTTP-based CLI to work over SSL

     # workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
     add_header 'X-SSH-Endpoint' 'build.example.de:50022' always;
    }

}

server {
    if ($host = build.example.de) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;

    server_name build.example.de;
    return 404; # managed by Certbot
}

我总是收到错误:

[error] 8441#8441: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 88.65.0.115, server: build.example.de, request: "GET / HTTP/1.1", upstream: "https://127.0.0.1:8090/", host: "build.example.de"


Jul 26 16:32:10 v22018076557869542 systemd[1]: Starting LSB: Start Jenkins at boot time...
Jul 26 16:32:10 v22018076557869542 jenkins[24446]: Error: Unable to access jarfile jenkins-cli.jar
Jul 26 16:32:10 v22018076557869542 jenkins[24446]: Correct java version found
Jul 26 16:32:10 v22018076557869542 jenkins[24446]:  * Starting Jenkins Automation Server jenkins
Jul 26 16:32:10 v22018076557869542 su[24520]: Successful su for jenkins by root
Jul 26 16:32:10 v22018076557869542 su[24520]: + ??? root:jenkins
Jul 26 16:32:10 v22018076557869542 su[24520]: pam_unix(su:session): session opened for user jenkins by (u
Jul 26 16:32:10 v22018076557869542 su[24520]: pam_unix(su:session): session closed for user jenkins
Jul 26 16:32:11 v22018076557869542 jenkins[24446]:    ...done.
Jul 26 16:32:11 v22018076557869542 systemd[1]: Started LSB: Start Jenkins at boot time.

我做错了什么??

【问题讨论】:

    标签: ssl nginx jenkins vps bad-gateway


    【解决方案1】:

    看起来您的请求被重定向到上游:“https://127.0.0.1:8090/”,虽然它应该是简单的 http,但尝试删除 proxy_redirect http:// https://;

    【讨论】:

    • 你能在本地向 jenkins 发出请求,以确保它正常工作,就像这样curl http://127.0.0.1:8090
    • curl: (7) 无法连接到 127.0.0.1 端口 8090: Connection denied 这是输出
    • 这意味着你的Jenkins没有监听这个端口,你是怎么改变端口的?
    • 哇哦好吧..我改变了 /etc/default/jenkins 中的 $HTTP_PORT 变量并重新启动了 jenkins ..
    • 这是上述jenkins文件的最后一行:java -jar jenkins-cli.jarJENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT - -httpListenAddress=$HTTP_PORT"
    猜你喜欢
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 2019-06-05
    • 2015-08-10
    • 2016-01-22
    • 2021-11-19
    相关资源
    最近更新 更多