Alex Bran
Alex Bran

Reputation: 463

How to run jenkins behing NGINX?

I am trying to configure Jenkins to be accessed only behind NGINX.

Currently Jenkins works on port 8080 which is exposed to run without SSL.

I have tried the following configuration:

        location /jenkins/ {
            proxy_pass  http://127.0.0.1:8080;
        }

If I try to access my url/jenkins it returns a 404 while trying to direct to jenkins login page. The 404 is being returned by the nextJs app working on / location of the NGINX server.

Both Nginx and Jenkins are running in Docker containers.

Upvotes: 0

Views: 315

Answers (1)

ycr
ycr

Reputation: 14604

First, you have to configure Jenkins with a context path. You can do this by passing a launch parameter --prefix=/jenkins. Then your NginX rule should work.

docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JENKINS_OPTS="--prefix=/jenkins" jenkins/jenkins:lts

If you still get any invalid redirects Try adding a proxy_redirect to your Nginx configurations. Which will rewrite all redirect URLs with the correct context.

Upvotes: 1

Related Questions