# Ssh-tunnel into website nginx strips out port number in response

**URL:** <https://www.ruby-forum.com/t/ssh-tunnel-into-website-nginx-strips-out-port-number-in-response/220038>\
**Category:** NGINX\
**Created:** [May 25, 2012, 9:30am UTC](https://www.ruby-forum.com/t/ssh-tunnel-into-website-nginx-strips-out-port-number-in-response/220038 "2012-05-25T09:30:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [May 25, 2012, 9:30am UTC](https://www.ruby-forum.com/t/ssh-tunnel-into-website-nginx-strips-out-port-number-in-response/220038/1 "2012-05-25T09:30:29Z")

</div>

Same post is made here:

> <https://serverfault.com/questions/392530/nginx-when-tunnel-the-url-redirects-without-port-number>

But I will make a shorter version (as much as possible)

I want to be able to ssh-tunnel into my Django website, so I can work  
remotely. I’ve tested a simple Django project on my personal computer,  
with  
very simple nginx configuration (starter, default). I tunnel and  
redirection returns with port number as part of the url. So I am sure  
this  
is not a Django problem. It’s mainly my nginx configuration.

Relevant code:

server {

> ```
> # the forum service runs as local, listens to 8000 port...
> proxy_pass http://localhost:8000;
> proxy_redirect default;
> 
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> 
> ```
> 
> }

Then I ssh-tunnel, open the browser, [http://localhost:1111](http://localhost:1111), and when I  
login, or do anything that requires redirection, I get  
[http://localhost/forum/front-page](http://localhost/forum/front-page) [http://yahoo.com/](http://yahoo.com/) instead of  
[http://localhost:1111/froum/front-page](http://localhost:1111/froum/front-page) [http://yahoo.com/](http://yahoo.com/)

These links are wrong, nginx will complain (from the server side) they  
do  
not exist.

I’ve tried stuff like

proxy\_set\_header $host:$server\_port; # or  
proxy\_set\_header $proxy\_host:$proxy\_port; # or  
proxy\_set\_header $host:$proxy\_port; # or  
rewrite ^(._):(._)/forum(._)$ /$2 last;  
 #rewrite ^/forum(._)$ $1 break;  
proxy\_redirect [http://localhost/](http://localhost/) http://$host:$proxy\_port;

The 2nd proxy\_set\_header shows a little progress. After pressing submit,  
I  
get a blank page, with the original url ([http://localhost:1111/post](http://localhost:1111/post) and  
then I see the same url again).

Any idea how to resolve my problem? Thanks.

John

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [May 26, 2012, 9:02am UTC](https://www.ruby-forum.com/t/ssh-tunnel-into-website-nginx-strips-out-port-number-in-response/220038/2 "2012-05-26T09:02:35Z")

</div>

So I came up with a simple solution…as my own answer…

proxy\_set\_header Host $host;

$host should be replaced with $http\_host, although I am not quite sure  
the meaning of either.

Posted at Nginx Forum:

> **[Re: ssh-tunnel into website nginx strips out port number in response](https://forum.nginx.org/read.php?2,226823,226849#msg-226849)**
>
> Same post is made here: http://serverfault.com/questions/392530/nginx-when-tunnel-the-url-redirects-without-port-number But I will make a shorter version (as much as possible) I want to be able to ssh-tunnel into my Django website, so I can work...
