【问题标题】:How to set up Jenkins with Nginx and a Node.js application如何使用 Nginx 和 Node.js 应用程序设置 Jenkins
【发布时间】:2017-11-28 15:51:53
【问题描述】:

我想要什么

您好,我的问题如下:我想通过浏览器 https://my-domain.com/jenkins 访问我在服务器上运行的 Jenkins。

我有什么

我有运行 Nginx 的 Ubuntu 16.04 的 DO droplet,它充当代理服务器,通过 https 将所有流量转发到我的 Node.js 应用程序,效果很好当我通过https://my-domain.com访问我的网站时。

我已经成功安装并运行了 Jenkins(如果我运行 systemctl status jenkins 我可以看到它处于活动状态),但是我不知道应该如何配置我的 Nginx 以正确访问 Jenkins。

我尝试为它设置一个新位置,但结果是,如果我访问 https://my-domain.com/jenkins,它会重定向到 https://my-domain.com/login?from=%2Fjenkins 并为我的 Node.js 应用程序提供服务。

Nginx 配置 (/etc/nginx/sites-enabled/default)

 server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;
        return 301 https://$host$request_uri;
    }

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name my-domain.com;

    # Access and error log for Jenkins
    access_log /var/log/nginx/jenkins.access.log;
    error_log /var/log/nginx/jenkins.error.log;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/my-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/my-domain.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://localhost:5000/;
    proxy_ssl_session_reuse off;
    proxy_set_header Host $http_host;
    proxy_cache_bypass $http_upgrade;
    proxy_redirect off;

    # Settings for Jenkins
    # include /etc/nginx/proxy_params;
    # proxy_pass http://localhost:8080;
    # proxy_read_timeout 90s;
    # proxy_redirect http://localhost:8080 https://my-domain.com;
}


location /jenkins {
    include /etc/nginx/proxy_params;
    proxy_pass http://localhost:8080;
    proxy_read_timeout 90s;
}
}

也许真正的问题不在于 Nginx 配置,而在于 Jenkins?提前致谢!

【问题讨论】:

    标签: node.js ubuntu nginx jenkins digital-ocean


    【解决方案1】:

    好的,我想通了。我意识到我必须使用proxy_pass http://localhost:8080/jenkins/; 而不是proxy_pass http://localhost:8080;,并使用proxy_redirect http:// https://; 重定向到https

    如需进一步帮助,请访问:https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2023-03-17
      • 2021-12-09
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多