如何使用 Nginx 和 Node.js 应用程序设置 Jenkins
How to set up Jenkins with Nginx and a Node.js application
我想要的
您好,我的问题如下:我想通过浏览器 https://my-domain.com/jenkins
.
访问服务器上 运行ning 的 Jenkins
我有什么
我有 Ubuntu 16.04 的 DO droplet 运行s Nginx 作为代理服务器,将所有流量转发到我的 Node.js 通过 https 申请,当我在 https://my-domain.com
.
访问我的网站时,它工作正常
我已经成功安装和 运行 Jenkins(如果我 运行 a 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?提前致谢!
好的,我已经弄明白了。我意识到我必须使用 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
我想要的
您好,我的问题如下:我想通过浏览器 https://my-domain.com/jenkins
.
我有什么
我有 Ubuntu 16.04 的 DO droplet 运行s Nginx 作为代理服务器,将所有流量转发到我的 Node.js 通过 https 申请,当我在 https://my-domain.com
.
我已经成功安装和 运行 Jenkins(如果我 运行 a 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?提前致谢!
好的,我已经弄明白了。我意识到我必须使用 proxy_pass http://localhost:8080/jenkins/;
而不是 proxy_pass http://localhost:8080;
,并使用 proxy_redirect http:// https://;
如需进一步帮助,请访问:https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy