【问题标题】:NGINX/JENKINS: It appears that your reverse proxy set up is brokenNGINX/JENKINS:您的反向代理设置似乎已损坏
【发布时间】:2018-06-24 04:33:50
【问题描述】:

我已经尝试了至少半个关于如何让 NGINX 与 Jenkins 一起工作的示例。我最近的 NGINX 配置基于以下示例:

https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+behind+Nginx

无论我尝试什么,Jenkins 一直在说 It appears that your reverse proxy set up is broken. 我希望有人能发现问题所在,因为我花了数小时试图解决这个问题,但无济于事。

谢谢!

upstream cicd {
        keepalive 32;
        server 127.0.0.1:8080;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl ipv6only=on;

        server_name cicd.domain.com;

        root /var/run/jenkins/war/;

        access_log /var/log/nginx/jenkins/access.log;
        error_log /var/log/nginx/jenkins/error.log;

        ssl_certificate /etc/letsencrypt/live/cicd.domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/cicd.domain.com/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

        #static files
        location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
                rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
        }

        #user content
        location /userContent {
                root /var/lib/jenkins/;

                if (!-f $request_filename){
                        rewrite (.*) /$1 last;
                        break;
                }
                sendfile on;
        }

        #cicd
        location @cicd {
                sendfile off;
                proxy_pass              http://cicd;
                proxy_redirect          http://localhost:8080 https://cicd.domain.com;
                proxy_http_version      1.1;

                proxy_set_header        Host                    $host;
                proxy_set_header        X-Real-IP               $remote_addr;
                proxy_set_header        X-Forwarded-Host        $host;
                proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto       $scheme;
                proxy_max_temp_file_size 0;

                client_max_body_size            10m;
                client_body_buffer_size         128k;

                proxy_connect_timeout           90;
                proxy_send_timeout              90;
                proxy_read_timeout              90;
                proxy_buffering                 off;
                proxy_request_buffering         off;
                proxy_set_header Connection     "";
        }

        #optional
        location / {
                if ($http_user_agent ~* '(iPhone|iPod)') {
                        rewrite ^/$ /view/iphone/ redirect;
                }

                try_files $uri @cicd;
        }

}

【问题讨论】:

  • 不是说就是这个,但是你检查过配置的Jenkins URL是否正确吗?检查 Jenkins -> 管理 Jenkins -> 配置系统 => Jenkins URL。如果它是错误的,那么您会收到错误消息。
  • 实际上,这正是问题所在。当我设置 Jenkins 时,它使用的是 IP,然后我切换到域。很好的收获。
  • 将此转换为答案。

标签: nginx jenkins


【解决方案1】:

这不是 NGINX 问题。

在 Jenkins 中,您需要配置 Jenkins URL。如果设置不正确,您将收到您观察到的错误。
检查 Jenkins -> 管理 Jenkins -> 配置系统 => Jenkins URL。

【讨论】:

  • 非常感谢,我找不到问题,但现在我记得我忘记更新网址了。
【解决方案2】:

对我来说,URL 配置正确。我不得不更改 Nginx 配置以包含一些额外的标头:

server {
    listen 443 ssl;
    
    server_name  my-subdomain.main-domain.com; # this is the url domain of the proxy (Load balancer in front of Jenkins)
    
    ssl_certificate /etc/nginx/certs/ssl_certificate.crt;
    ssl_certificate_key /etc/nginx/certs/ssl_key.pem;
    
    location / {

        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Host my-subdomain.main-domain.com; # this is the url domain of the proxy (Load balancer in front of Jenkins)

        proxy_pass http://${JENKINS_PRIVATE_IP}:${JENKINS_PORT};
    }
}

【讨论】:

    【解决方案3】:

    对于 Linux (Ubuntu) 用户,请检查 /etc/default/jenkins 文件。

    在该文件中,查找 JENKINS_ARGS 并复制 httpListenAddress 并将其粘贴到您的 Jenkins URL 中。

    我正在使用带有 Lets Encrypt 加密的 Nginx,我的 /etc/default/jenkins 文件是这样的 JENKINS_ARGS="--webroot=/var/cache/$NAME/war - -httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"

    我想你也可以 localhost:[your port] 或 127.0.0.1:[your port]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 2016-10-17
      • 2013-05-23
      • 2020-03-18
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      相关资源
      最近更新 更多