# Problem with double slashes in URL when using nginx as proxy

**URL:** <https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273>\
**Category:** NGINX\
**Created:** [July 27, 2010, 2:38pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273 "2010-07-27T14:38:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [July 27, 2010, 2:38pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/1 "2010-07-27T14:38:41Z")

</div>

Hi all,

I have web server where nginx is using as proxy for PHP scripts and web  
server for static files. I use the following configuration:

server {  
listen 80;  
server\_name _**.com;  
access\_log /var/log/nginx/**_.com.access\_log;  
location ~\*  
.(jpg|jpeg|gif|png|css|js|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)(?.+)?$  
{  
root /var/www/\*\*\*\*\*\*\*\*\*\*.com/public/;  
index index.html index.php;  
expires max;  
access\_log off;  
}  
location ~ /.ht {  
deny all;  
}  
location / {  
proxy\_pass [http://127.0.0.1:8080/](http://127.0.0.1:8080/);  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-for $remote\_addr;  
proxy\_set\_header Host $host;  
proxy\_connect\_timeout 60;  
proxy\_send\_timeout 90;  
proxy\_read\_timeout 90;  
proxy\_redirect off;  
proxy\_set\_header Connection close;  
proxy\_pass\_header Content-Type;  
proxy\_pass\_header Content-Disposition;  
proxy\_pass\_header Content-Length;  
}  
}

Also there is apache2 running on port 8080 and process all non static  
requests.

The problem in following - when I request  
/en/all/all/filtered/246/1/date///-1//0 in logs of apache I see:

**.**._._\*\* - - [27/Jul/2010:12:33:48 +0000] “GET  
/en/all/all/filtered/246/1/date/-1/0 HTTP/1.0” 200 11548 “-”  
“Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8)  
Gecko/20100722 Firefox/3.6.8 GTB7.1”

Please notice that there is no double slashes already. Apache gets  
“/en/all/all/filtered/246/1/date/-1/0” instead of requested  
“/en/all/all/filtered/246/1/date///-1//0”. And it creates problems in  
the code.

And when I request Apache directly with  
:8080/en/all/all/filtered/246/1/date///-1//0 it just works Ok. So I  
suppose double slashes are missed somewhere in nginx.

I have nginx/0.7.67 installed.

Any ideas will be appreciated. Thanks!

Posted at Nginx Forum:

> **[Problem with double slashes in URL when using nginx as proxy](https://forum.nginx.org/read.php?2,113427,113427#msg-113427)**
>
> Hi all, I have web server where nginx is using as proxy for PHP scripts and web server for static files. I use the following configuration: server { listen 80; server\_name \*\*\*\*\*\*\*\*\*.com; access\_log /var/log/nginx/\*\*\*\*\*\*\*\*\*.co

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [July 27, 2010, 2:42pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/2 "2010-07-27T14:42:47Z")

</div>

On Tue, Jul 27, 2010 at 08:37:15AM -0400, alexk wrote:

> .(jpg|jpeg|gif|png|css|js|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)(?.+)?$  
> proxy\_pass [http://127.0.0.1:8080/](http://127.0.0.1:8080/);

- 

```
            proxy_pass http://127.0.0.1:8080/;

```

- 

```
            proxy_pass http://127.0.0.1:8080;

```

> ```
> proxy_pass_header Content-Length;
> 
> ```
> 
> /en/all/all/filtered/246/1/date/-1/0 HTTP/1.0" 200 11548 “-”  
> suppose double slashes are missed somewhere in nginx.
> 
> I have nginx/0.7.67 installed.
> 
> Any ideas will be appreciated. Thanks!

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [July 27, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/3 "2010-07-27T16:34:37Z")

</div>

Strange but it fixed the problem. Thanks a lot!

Posted at Nginx Forum:

> **[Re: Problem with double slashes in URL when using nginx as proxy](https://forum.nginx.org/read.php?2,113427,113455#msg-113455)**
>
> Hi all, I have web server where nginx is using as proxy for PHP scripts and web server for static files. I use the following configuration: server { listen 80; server\_name \*\*\*\*\*\*\*\*\*.com; access\_log /var/log/nginx/\*\*\*\*\*\*\*\*\*.co

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [September 10, 2010, 2:06pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/4 "2010-09-10T14:06:10Z")

</div>

Strange,

When post is specified in listen directive:

server {  
listen 80;  
…  
}

it works well with double slashes.

But when using domain name in listen directive

server {  
listen \*\*\*\*\*.com;  
…  
}

it removes double slashes.

Posted at Nginx Forum:

> **[Re: Problem with double slashes in URL when using nginx as proxy](https://forum.nginx.org/read.php?2,113427,129135#msg-129135)**
>
> Hi all, I have web server where nginx is using as proxy for PHP scripts and web server for static files. I use the following configuration: server { listen 80; server\_name \*\*\*\*\*\*\*\*\*.com; access\_log /var/log/nginx/\*\*\*\*\*\*\*\*\*.co

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [September 10, 2010, 2:13pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/5 "2010-09-10T14:13:12Z")

</div>

Sorry vice versa 🙂

With domain name it works well. But when port is specified in listen it  
removes double slashes.

Posted at Nginx Forum:

> **[Re: Problem with double slashes in URL when using nginx as proxy](https://forum.nginx.org/read.php?2,113427,129139#msg-129139)**
>
> Hi all, I have web server where nginx is using as proxy for PHP scripts and web server for static files. I use the following configuration: server { listen 80; server\_name \*\*\*\*\*\*\*\*\*.com; access\_log /var/log/nginx/\*\*\*\*\*\*\*\*\*.co

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [September 10, 2010, 2:17pm UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/6 "2010-09-10T14:17:18Z")

</div>

On Fri, Sep 10, 2010 at 08:05:13AM -0400, alexk wrote:

> But when using domain name in listen directive
> 
> server {  
> listen \*\*\*\*\*.com;  
> …  
> }
> 
> it removes double slashes.

You probably proxy using

```
location / {
    proxy_pass http://backend/;
}

```

You need ot remove the last “/”, then nginx will use a client original  
request with double slashes:

```
location / {
    proxy_pass http://backend;
}

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![alexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@alexk](https://www.ruby-forum.com/u/alexk)\
**Post date:** [September 17, 2010, 1:03am UTC](https://www.ruby-forum.com/t/problem-with-double-slashes-in-url-when-using-nginx-as-proxy/192273/7 "2010-09-17T01:03:09Z")

</div>

Igor,

I’ve already replaced it to proxy\_pass [http://127.0.0.1:8080](http://127.0.0.1:8080); after your  
first post.

And now when I change it to:

server {  
listen 80;  
…  
}

It removes double slashes.

With domain name it works just well.

Thanks,  
Alex

Posted at Nginx Forum:

> **[Re: Problem with double slashes in URL when using nginx as proxy](https://forum.nginx.org/read.php?2,113427,131146#msg-131146)**
>
> Hi all, I have web server where nginx is using as proxy for PHP scripts and web server for static files. I use the following configuration: server { listen 80; server\_name \*\*\*\*\*\*\*\*\*.com; access\_log /var/log/nginx/\*\*\*\*\*\*\*\*\*.co
