# Proxy pass with rewrite

**URL:** <https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107>\
**Category:** NGINX\
**Created:** [October 25, 2013, 7:57am UTC](https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107 "2013-10-25T07:57:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [October 25, 2013, 7:57am UTC](https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107/1 "2013-10-25T07:57:42Z")

</div>

Hello,

I would like to configure ngix with jenkins, nginx should be a proxy for  
the jenkins instance. I have configuration the proxy pass options in  
this way:

```
location /jenkins {
    proxy_pass http://localhost:8080/;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

```

My jenkins instance uses the port 8080 and I would like to pass the data  
from the URL [http://mydomain/jenkins](http://mydomain/jenkins) to the jerkins instance.  
If I change the location to / everything works fine, but with the  
subdirectory alias I get an error with the URL. Jenkins result pages  
uses only  
URLs to [http://mydomain/](http://mydomain/) but in my case it should be  
[http://mydomain/jenkins/](http://mydomain/jenkins/)  
I have modified the Jenkins URL (in the admin panel) to  
[http://mydomain/jenkins/](http://mydomain/jenkins/) but it seems to be an error on the reverse data  
call.  
I must substitute all URL, which comes from the proxy\_pass URL with  
[http://mydomain/jenkins](http://mydomain/jenkins)  
How can I do this in a correct way?

Thanks

Phil

---

<div class="post-metadata">

**Author:** ![Philipp\_Kraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f1d935/32.png) [@Philipp\_Kraus](https://www.ruby-forum.com/u/Philipp_Kraus)\
**Post date:** [October 25, 2013, 10:02am UTC](https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107/2 "2013-10-25T10:02:10Z")

</div>

On Fri, Oct 25, 2013 at 07:57:01AM +0200, Philipp Kraus wrote:

Hi there,

> I would like to configure ngix with jenkins, nginx should be a proxy for the  
> jenkins instance. I have configuration the proxy pass options in this way:

> **[Reverse proxy configuration](https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-with-jenkins/)**
>
> Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software

looks like it may have useful information.

> If I change the location to / everything works fine, but with the subdirectory  
> alias I get an error with the URL. Jenkins result pages uses only  
> URLs to [http://mydomain/](http://mydomain/) but in my case it should be  
> [http://mydomain/jenkins/](http://mydomain/jenkins/)

Fix jenkins so that it knows it is below /jenkins/, not below /.

> I must substitute all URL, which comes from the proxy\_pass URL with  
> [http://mydomain/jenkins](http://mydomain/jenkins)  
> How can I do this in a correct way?

The best way in general is to arrange the back-end so that it doesn’t  
need doing.

## f

Francis D. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Philipp\_Kraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f1d935/32.png) [@Philipp\_Kraus](https://www.ruby-forum.com/u/Philipp_Kraus)\
**Post date:** [October 25, 2013, 1:26pm UTC](https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107/3 "2013-10-25T13:26:08Z")

</div>

Hi,

Am 25.10.2013 um 10:01 schrieb Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

> **[Reverse proxy configuration](https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-with-jenkins/)**
>
> Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software

> looks like it may have useful information.

I have used this how to, but I cannot create a working solution

> Fix jenkins so that it knows it is below /jenkins/, not below /.

I have set in Jenkins System panel the field “Jenkins URL” to  
“myserver/jenkins/”

Any URLs are working correct but other are working. CSS are not working  
because the /jenkins/ part  
is not exists. So it seems that nginx removes on some URL the /jenkins/  
part in the URL

Phil

---

<div class="post-metadata">

**Author:** ![Philipp\_Kraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f1d935/32.png) [@Philipp\_Kraus](https://www.ruby-forum.com/u/Philipp_Kraus)\
**Post date:** [October 25, 2013, 1:43pm UTC](https://www.ruby-forum.com/t/proxy-pass-with-rewrite/237107/4 "2013-10-25T13:43:40Z")

</div>

On Fri, Oct 25, 2013 at 01:25:10PM +0200, Philipp Kraus wrote:

> Am 25.10.2013 um 10:01 schrieb Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

Hi there,

> >

> **[Reverse proxy configuration](https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-with-jenkins/)**
>
> Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software

> > looks like it may have useful information.
> 
> I have used this how to, but I cannot create a working solution

The config in this howto, and the config that you showed, are not the  
same.

Note particularly the “location” and the “proxy\_pass” lines.

> > Fix jenkins so that it knows it is below /jenkins/, not below /.
> 
> I have set in Jenkins System panel the field “Jenkins URL” to  
> “myserver/jenkins/”

The howto say to do something else as well.

I don’t know if it is correct – I don’t use Jenkins – but I also don’t  
know what you’ve done, because you haven’t said.

> Any URLs are working correct but other are working. CSS are not working because  
> the /jenkins/ part  
> is not exists. So it seems that nginx removes on some URL the /jenkins/ part in  
> the URL

That could be due to proxy\_pass.

[http://nginx.org/r/proxy\_pass](http://nginx.org/r/proxy_pass)

“specified with a URI” means “any slash after the host:port part”.

If that doesn’t fix things, then can you find one request which does  
not work as you expect it to, and show what url nginx gets, and what  
url jenkins gets, and see if that helps find where things go wrong?

Good luck with it,

## f

Francis D. removed\_email\_address@domain.invalid
