'Jenkins + Nginx + sub domain without context

I would like to access jenkins via my.domain.fr without never see the "jenkins" context. Is this possible exclusively with Nginx configuration ?

I have found some interesting links :

But it doesn't work. The best I can have is a direct access to jenkins from my.domain.fr, and as soon as I click somewhere the "jenkins" context appears. My configuration works but seems ugly because a duplication. Moreover I got the jenkins message :

It appears that your reverse proxy set up is broken

This message is due to the "jenkins" context added on the proxy_pass. But I don't know how I could do without it.

Current configuration :

server {
  listen 80;
  listen [::]:80;
  server_name my.domain.fr;
  return 301 https://$host$request_uri;
}

server {
  listen  443;
  listen  [::]:443;
  server_name my.domain.fr;

  location /jenkins/ {
    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://127.0.0.1:8080/jenkins/;
  }

  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://127.0.0.1:8080/jenkins/;
  }
}


Solution 1:[1]

server {
  listen 80;
  listen [::]:80;
  server_name my.domain.fr;
  return 301 https://$host$request_uri;
}

server {
  listen  443;
  listen  [::]:443;
  server_name my.domain.fr;

  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://127.0.0.1:8080/;
  }
}

Anything going to / is being passed to /jenkins, which is causing your issue. Simply remove the /jenkins block and update your proxy_pass declaration. This should resolve your issue, though you may still need to tweak some Jenkins internal settings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 796m9XfYTkmp