Search code examples
nginxjenkinshttp-status-code-404reverse-proxyplesk

Jenkins + nginx reverse proxy on Plesk


I'm running Plesk Obsidian on my centOS server and manually installed Jenkins on it. Jenkins is up and running. It can be used by calling http://my-server.de:38080 without any problems. I also created a new subdomain in Plesk (jenkins.my-server.de), which is secured with a lets encrypt certificate.

My idea was to use the nginx reverse proxy to call Jenkins using the new subdomain: https://jenkins.my-server.de. Therefore I disabled the use of Apache in the Plesk Apache & nginx Settings for the subdomain and added the following additional nginx directives in the Plesk web interface:

location ~ / {
  proxy_pass          http://localhost:38080;
  proxy_read_timeout  90;

  proxy_redirect      http://localhost:38080 https://jenkins.my-server.de;
}

The problem is, that some sites are working and on other sites I get a 404.

Calling https://jenkins.my-server.de should show me the login page, but I get a 404. Only if I enter https://jenkins.my-server.de/index in the browser, I see the login page. Calling https://jenkins.my-server.de/manage on the other hand loads the wanted page without error. The page https://jenkins.my-server.de/configureSecurity shows a 404 again and only works if I add /index at the end.

Am I missing something in the nginx settings?


Solution

  • The following configuration is working for me in combination with Plesk.

    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_redirect          http://localhost:38080 https://jenkins.my-server.de;
        proxy_pass              http://localhost:38080;
    
        proxy_http_version 1.1;
        proxy_request_buffering off;
        proxy_buffering off;
        add_header 'X-SSH-Endpoint' 'jenkins.my-server.de:50022' always;
    }