如何使用Nginx和Node.js应用程序设置Jenkins

时间:2017-06-25 17:49:58

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

我想要什么

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

我拥有什么

我有一个带有 Ubuntu 16.04运行Nginx 的小滴作为代理服务器,通过https 将所有流量转发到我的 Node.js应用程序,工作正常当我在https://my-domain.com访问我的网站时。

我已成功安装并运行Jenkins(如果我运行systemctl status jenkins我可以看到它处于活动状态),但我无法弄清楚,我的Nginx应该如何配置才能访问詹金斯说得对。

我尝试做的是为它设置一个新位置,但结果是,如果我访问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?提前谢谢!

1 个答案:

答案 0 :(得分:0)

好的,我已经弄清楚了。我意识到我不得不proxy_pass http://localhost:8080;使用proxy_pass http://localhost:8080/jenkins/;,而是使用proxy_redirect http:// https://;重定向到https

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