# Proxy\_pass and slash witch nginx

**URL:** <https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115>\
**Category:** NGINX\
**Created:** [May 18, 2011, 6:11pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115 "2011-05-18T18:11:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 18, 2011, 6:11pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115/1 "2011-05-18T18:11:46Z")

</div>

Hello,

I set up a reverse proxy for a client with Nginx.

I still have a problem when I click on a link but the name of the  
directory doesn’t end with a slash.

The proxy address is [http://proxy.com](http://proxy.com) and all requests are returned to  
[http://mydomain.com](http://mydomain.com)

Example: [Proxy](http://proxy.com/test/) and reference works well inside  
[http://mydomain.com](http://mydomain.com) but remains on [Proxy](http://proxy.com/test/)

If I remove the slash of the end I don’t have [Proxy](http://proxy.com/test) in  
the address bar but [http://mydomain.com/test/](http://mydomain.com/test/) (with slash at the end  
because the other web server adds).

In the http headers I see a 301 but it is not handled by nginx visibly:

[http://proxy.com/test](http://proxy.com/test)

GET /test HTTP/1.1

Host: [proxy.com](http://proxy.com)  
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101  
Firefox/4.0.1

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip, deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.7

Keep-Alive: 115

Connection: keep-alive

Cookie: language1=en; language2=en

HTTP/1.1 301 Moved Permanently

Server: nginx/0.7.67

Date: Wed, 18 May 2011 07:15:57 GMT

Content-Type: text/html; charset=iso-8859-1

Transfer-Encoding: chunked

Connection: keep-alive

Location: [http://mydomain.com/test/](http://mydomain.com/test/)

Age: 108

I thought to rewrite the rules but it might cause trouble.

If anyone has an idea on the subject, I’m interested.

Thank you

Posted at Nginx Forum:

> **[Proxy\_pass and slash witch nginx](https://forum.nginx.org/read.php?2,198964,198964#msg-198964)**
>
> Hello, I set up a reverse proxy for a client with Nginx. I still have a problem when I click on a link but the name of the directory doesn't end with a slash. The proxy address is http://proxy.com and all requests are returned to http://mydomain.com

---

<div class="post-metadata">

**Author:** ![myckeul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@myckeul](https://www.ruby-forum.com/u/myckeul)\
**Post date:** [May 18, 2011, 9:51pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115/2 "2011-05-18T21:51:04Z")

</div>

Hello!

On Wed, May 18, 2011 at 12:11:33PM -0400, myckeul wrote:

> Example: [http://proxy.com/test/](http://proxy.com/test/) and reference works well inside
> 
> GET /test HTTP/1.1  
> Host: [proxy.com](http://proxy.com)

[…]

> HTTP/1.1 301 Moved Permanently

[…]

> Location: [http://mydomain.com/test/](http://mydomain.com/test/)
> 
> Age: 108
> 
> I thought to rewrite the rules but it might cause trouble.
> 
> If anyone has an idea on the subject, I’m interested.

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.

---

<div class="post-metadata">

**Author:** ![myckeul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@myckeul](https://www.ruby-forum.com/u/myckeul)\
**Post date:** [May 19, 2011, 10:37pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115/3 "2011-05-19T22:37:58Z")

</div>

Hello,

Thanks for your response but they won’t working.

Here is my conf :

nginx.conf :  
user www-data;  
worker\_processes 1;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
# multi\_accept on;  
}

http {  
include /etc/nginx/mime.types;

```
access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

```

}

my vhost :  
server {  
listen [::]:80;

```
   server_name proxy.com *.proxy.com;

   access_log /var/log/nginx/proxy_.access.log;

   error_page 404 = /404.htm;

   location /404.htm {
     root /var/www;
   }

   location / {
       proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

if ($host ~* ^proxy\.com$) {
   proxy_pass http://mydomain.com;
}

if ($host ~* ^www\.proxy\.com$) {
   proxy_pass http://www.mydomain.com;
}

if ($host ~* ^subdomain\.proxy\.com$) {
   proxy_pass http://subdomain.mydomain.com;
}

proxy_redirect http://proxy.com/test http://proxy.com/test/;

```

}  
}

and my proxy.conf file :  
proxy\_redirect off;  
proxy\_intercept\_errors on;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
client\_max\_body\_size 10m;  
client\_body\_buffer\_size 128k;  
client\_header\_buffer\_size 64k;  
proxy\_connect\_timeout 90;  
proxy\_send\_timeout 90;  
proxy\_read\_timeout 90;  
proxy\_buffer\_size 16k;  
proxy\_buffers 32 16k;  
proxy\_busy\_buffers\_size 64k;

Thanks for your help

Posted at Nginx Forum:

> **[Re: Proxy\_pass and slash witch nginx](https://forum.nginx.org/read.php?2,198964,199196#msg-199196)**
>
> Hello, I set up a reverse proxy for a client with Nginx. I still have a problem when I click on a link but the name of the directory doesn't end with a slash. The proxy address is http://proxy.com and all requests are returned to http://mydomain.com

---

<div class="post-metadata">

**Author:** ![myckeul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@myckeul](https://www.ruby-forum.com/u/myckeul)\
**Post date:** [May 21, 2011, 4:10pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115/4 "2011-05-21T16:10:02Z")

</div>

hello 😉

thank you, everything is ok now

have a nice day

Posted at Nginx Forum:

> **[Re: Proxy\_pass and slash witch nginx](https://forum.nginx.org/read.php?2,198964,199488#msg-199488)**
>
> Hello, I set up a reverse proxy for a client with Nginx. I still have a problem when I click on a link but the name of the directory doesn't end with a slash. The proxy address is http://proxy.com and all requests are returned to http://mydomain.com

---

<div class="post-metadata">

**Author:** ![myckeul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@myckeul](https://www.ruby-forum.com/u/myckeul)\
**Post date:** [May 20, 2011, 1:07pm UTC](https://www.ruby-forum.com/t/proxy-pass-and-slash-witch-nginx/207115/5 "2011-05-20T13:07:16Z")

</div>

On Thu, May 19, 2011 at 04:37:38PM -0400, myckeul wrote:

> Hello,
> 
> Thanks for your response but they won’t working.

> ```
> location /404.htm {
> proxy_pass http://mydomain.com;
> proxy_redirect http://proxy.com/test http://proxy.com/test/;
> 
> ```
> 
> }  
> }

proxy\_redirect [http://mydomain.com](http://mydomain.com) [http://proxy.com](http://proxy.com);  
proxy\_redirect [http://www.mydomain.com](http://www.mydomain.com) [http://www.proxy.com](http://www.proxy.com);  
proxy\_redirect [http://subdomain.mydomain.com](http://subdomain.mydomain.com) [http://subdomain.proxy.com](http://subdomain.proxy.com);

BTW, your configuraiton is wrong mix of levels: you should not use  
virtual host name on location level in “if ($host ~”. This leads  
to cumbersome and unmaintainable configurations.  
Instead you should define 3 separate servers:

server {  
server\_name [proxy.com](http://proxy.com);  
location / {  
proxy\_pass [http://mydomain.com](http://mydomain.com);  
}  
…  
}

server {  
server\_name [www.proxy.com](http://www.proxy.com);  
location / {  
proxy\_pass [http://www.mydomain.com](http://www.mydomain.com);  
}  
…  
}

server {  
server\_name [subdomain.proxy.com](http://subdomain.proxy.com);  
location / {  
proxy\_pass [http://subdomain.mydomain.com](http://subdomain.mydomain.com);  
}  
…  
}

–  
Igor S.
