Running Jenkins behind NGINX Proxy

I have a Jenkins server with a private IP address and an NGNIX server with a public IP. I wanted to point the domain for the Jenkins server to the NGINX server and the NGINX server would forward the request the Jenkins server.

I got this working through NGINX proxy pass, here is NGNIX configuration that I have used to get it working.

Assume the domain used for Jenkins server is jenkins.mydomain.com and the IP address of the Jenkins server is 192.168.1.20 running at port 8080.

On the Nginx server we create the file under the sites-available folder, here is the exact path: /etc/nginx/sites-available/jenkins.mydomain.com

upstream jenkins {
	server 192.168.1.20:8080 fail_timeout=0;
}

server {
	listen 80;
	server_name jenkins.mydomain.com;

	location / {
		proxy_set_header	Host $host:$server_port;
		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://192.168.1.20:8080/ http://jenkins.mydomain.com/;
		# Required for new HTTP-based CLI
		proxy_http_version 1.1;
		proxy_request_buffering off;
		# workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
		add_header 'X-SSH-Endpoint' 'jenkins.mydomain.com:50022' always;
	}
}

Then linked the jenkins.mydomain.com file to sites-enabled

sudo ln -s /etc/nginx/sites-available/jenkins.mydomain.com /etc/nginx/sites-enabled/

Test the updated configuration

sudo nginx -t

Restart the nginx server

sudo systemctl restart nginx

That’s it! Let me know if you have any questions or comments.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *