Nginx reverse proxy URL getting rewritten

I am using nginx reverse proxy with ingress object to route my requests to kubernetes pod.

With the below config in place, when I place a request to http://myservices.myorg.com/jenkins

My request is going to http://myservices.myorg.com/login?from=%2F
But i want it to go to http://myservices.myorg.com/jenkins/login?from=%2F

So after I manually replaced to above correct path, all the resources like css, js are rendered with wrong path as http://myservices.myorg.com/static/beacae7e/css/simple-page.css

But it must be http://myservices.myorg.com/jenkins/static/beacae7e/css/simple-page.css

Similarly, after I logged in (I think http POST method) it is going to home page (in browser it changes from 
http://myservices.myorg.com/jenkins/login  to  
http://myservices.myorg.com/jenkins 

But all the resources rendered again are with wrong path (without /jenkins) -
http://myservices.myorg.com/static/beacae7e/css/layout-common.css

````
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
spec:
  rules:
  - host: myservices.myorg.com
    http:
      paths:
      - path: /jenkins
        backend:
           serviceName: jenkins
           service port: 80
````

And below is nginx.conf -

````
http {
server {
    listen 80;
    server_name ip-10-118-6-35.ec2.internal;
     location /jenkins {
       proxy_pass https://backend_nodes_jenkins/;
      }
   }
 upstream backend_nodes_jenkins {
    server 10.102.194.242:80;
  }
}

````
 

As you can see in above nginx.conf , in proxy_pass I am having slash at the end of the URL since I should not pass /jenkins to my pod. 

So this is working as expected but only issue is get requests are rewriting my url I believe. Please help.

chonthicha tutama's picture

Simple redirect

You can try to redirect the URL instead of changing it in code and create a path-alias.

Vote the answer: 
0
No votes yet
gopikrish81's picture

Simple redirect reply

You can try to redirect the URL instead of changing it in code and create a path-alias -  But I guess Jenkins application is rendering url with respect to domain name and not with respect to relative path. Like all the css and js are rendered with <domain>/css/simple-layout.css instead of <domain>/jenkins/css/simple-layout.css

So this /jenkins is getting lost I believe it's because my Jenkins pod doesn't know this path?

Vote the answer: 
0
No votes yet
gopikrish81's picture

Jenkins issue

Looks like Jenkins will generate hyperlinks like this. Read from this page - https://wiki.jenkins.io/display/JENKINS/Hyperlinks+in+HTML

So not sure how to proceed..

Vote the answer: 
0
No votes yet
gopikrish81's picture

Solution

Figured it out by passing as env variable in docker CMD - JENKINS_OPTS="--prefix=/jenkins"

Vote the answer: 
0
No votes yet