You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Jenkins迁移至NGINX反向代理后提示配置损坏求助

Fixing "It appears that your reverse proxy setup is broken" in Jenkins with NGINX

Hey there, let's work through this Jenkins reverse proxy issue together. That error almost always pops up when Jenkins can't confirm the reverse proxy is forwarding requests correctly—usually because of missing critical headers, misconfigured paths, or Jenkins not being told it's behind a proxy. Let's break down the fixes based on your config snippet:


1. Add Required Proxy Headers to NGINX

Your current config is missing the headers Jenkins needs to recognize the proxy. Drop this location block inside your server section (it's the most common fix for this error):

location / {
    # Tell Jenkins the original request details
    proxy_set_header        Host $host;
    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_pass              http://jenkins;
    proxy_read_timeout      90;

    # Fix proxy redirect mismatch
    proxy_redirect          http://jenkins http://your-domain.com; # Replace with your actual domain/IP
}

Note: If you plan to switch to HTTPS later, update the proxy_redirect value to https://your-domain.com.

2. Configure Jenkins to Trust the Proxy

Jenkins needs explicit confirmation that it's behind a proxy. You can set this two ways:

Option A: Update Jenkins Startup Arguments

Edit your Jenkins startup config (usually /etc/default/jenkins or a systemd service file) to add these flags:

JAVA_ARGS="-Djenkins.model.Jenkins.slaveAgentPort=50000 -Djava.awt.headless=true -Djenkins.proxy.host=127.0.0.1 -Djenkins.proxy.port=80 -Dno_proxy=localhost,127.0.0.1,your-domain.com"

Option B: Set via Jenkins UI (once accessible)

  • Go to Manage Jenkins > Configure System
  • Scroll to Jenkins Location
  • Set the Jenkins URL to your public address (e.g., http://your-domain.com)
  • Check "Enable proxy compatibility" (if the option exists)

3. Validate Your Full NGINX Config

Here's a complete, corrected version of your config to reference:

upstream jenkins {
    keepalive 32;
    server 127.0.0.1:8080; # Jenkins local port
}

server {
    listen 80;
    server_name your-domain.com; # Replace with your domain/IP

    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;
        proxy_set_header        X-Forwarded-Proto $scheme;

        proxy_pass              http://jenkins;
        proxy_read_timeout      90;
        proxy_redirect          http://jenkins http://your-domain.com;

        # Fix keepalive issues
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

    # Optional: Handle Jenkins agent JAR downloads
    location /jnlpJars/ {
        proxy_pass http://jenkins;
        proxy_set_header Host $host;
    }
}

4. Test and Reload Services

Always validate your NGINX config before applying changes:

nginx -t

If it passes, reload NGINX and restart Jenkins:

systemctl reload nginx
systemctl restart jenkins

5. Quick Network Checks

  • Confirm Jenkins is running locally: Run curl http://127.0.0.1:8080 on the server—you should see Jenkins' HTML output.
  • Ensure port 80 is open in your server's firewall (e.g., ufw allow 80 for Ubuntu).

After these steps, the reverse proxy error should vanish. If it sticks around, double-check that your Jenkins URL in the config matches exactly what you're using in your browser (including HTTP/HTTPS).

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

火山引擎 最新活动