# Nginx Can't get the request port when doing proxy

**URL:** <https://www.ruby-forum.com/t/nginx-cant-get-the-request-port-when-doing-proxy/214201>\
**Category:** NGINX\
**Created:** [November 24, 2011, 11:16am UTC](https://www.ruby-forum.com/t/nginx-cant-get-the-request-port-when-doing-proxy/214201 "2011-11-24T11:16:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 24, 2011, 11:16am UTC](https://www.ruby-forum.com/t/nginx-cant-get-the-request-port-when-doing-proxy/214201/1 "2011-11-24T11:16:52Z")

</div>

such as :  
Client(192.168.1.101) want visit [http://192.168.1.201:9000/myfile](http://192.168.1.201:9000/myfile)  
example,and need visit other ports.  
but client must use proxy to visit. Nginx is the proxyer!

```
Nginx proxy running on 192.168.1.202 and listen at port 8080 .
    I use '''proxy_pass $scheme://$host$request_uri;''' to make

```

proxy,but I get http-502 when I use this proxy-server.  
Becase nginx use the default port 80 to proxy:  
| request = [http://192.168.1.201:9000/myfile](http://192.168.1.201:9000/myfile)  
| proxy-server = 192.168.1.202 8080  
| proxy-to = [http://192.168.1.201:80/myfile](http://192.168.1.201:80/myfile)  
There are only $remote\_port and $server\_port on nginx-variables:  
[http://wiki.nginx.org/HttpCoreModule#Variables](http://wiki.nginx.org/HttpCoreModule#Variables)

```
If I just want visit port 9000 on 192.168.1.201,I can write by

```

‘’‘proxy\_pass $scheme://$host:9000$request\_uri;’‘’  
But it’s not a good idea ,and there are some other port to use.

```
How can I do ?

```

Posted at Nginx Forum:

> **[Nginx Can't get the request port when doing proxy](https://forum.nginx.org/read.php?2,218934,218934#msg-218934)**
>
> such as : Client(192.168.1.101) want visit http://192.168.1.201:9000/myfile example,and need visit other ports. but client must use proxy to visit. Nginx is the proxyer! Nginx proxy running on 192.168.1.202 and listen at port 8080 . I use '''p

---

<div class="post-metadata">

**Author:** ![higkoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8e8cbc/32.png) [@higkoo](https://www.ruby-forum.com/u/higkoo)\
**Post date:** [November 24, 2011, 11:28am UTC](https://www.ruby-forum.com/t/nginx-cant-get-the-request-port-when-doing-proxy/214201/2 "2011-11-24T11:28:03Z")

</div>

Hello!

On Thu, Nov 24, 2011 at 05:16:04AM -0500, higkoo wrote:

> ```
> | proxy-server = 192.168.1.202 8080
> | proxy-to = http://192.168.1.201:80/myfile
> There are only $remote_port and $server_port on nginx-variables:
> 
> ```
> 
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#Variables)
> 
> ```
> If I just want visit port 9000 on 192.168.1.201,I can write by
> 
> ```
> 
> ‘’‘proxy\_pass $scheme://$host:9000$request\_uri;’‘’  
> But it’s not a good idea ,and there are some other port to use.
> 
> ```
> How can I do ?
> 
> ```

Just a side note:

nginx isn’t forward proxy, it’s reverse proxy. By using nginx as  
a forward proxy you are looking for problems, including security  
ones.

Maxim D.

---

<div class="post-metadata">

**Author:** ![higkoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8e8cbc/32.png) [@higkoo](https://www.ruby-forum.com/u/higkoo)\
**Post date:** [November 25, 2011, 6:53am UTC](https://www.ruby-forum.com/t/nginx-cant-get-the-request-port-when-doing-proxy/214201/3 "2011-11-25T06:53:51Z")

</div>

Thanks , Maxim D…

Posted at Nginx Forum:

> **[Re: Nginx Can't get the request port when doing proxy](https://forum.nginx.org/read.php?2,218934,218999#msg-218999)**
>
> such as : Client(192.168.1.101) want visit http://192.168.1.201:9000/myfile example,and need visit other ports. but client must use proxy to visit. Nginx is the proxyer! Nginx proxy running on 192.168.1.202 and listen at port 8080 . I use '''p
