By Bootsie123


2019-02-09 17:06:19 8 Comments

In the long run what I'm trying to do is to be able to connect to any domain through any port, for example, mysite.com:8000 and then through Nginx have it get routed to an internal ip through the same port. So for example to 192.168.1.114:8000.

I looked into iptables although I'm planning on having multiple domains so that really doesn't work for me in this case (feel free to correct me if I'm wrong). I made sure that the internal ip and port that I'm trying to access is connectable and running and also that the ports I'm testing with are accessible from outside my network.

Here's my Nginx config that I'm currently using:

server {
   set $server "192.168.1.114";
   set $port $server_port;

   listen 80;
   listen 443;
   listen 9000;

   server_name mysite.com;

   location / {
      proxy_pass http://$server:$port;
      proxy_set_header Host $host:$server_port;
   }
}

Currently what happens is that when I send a request it just times out. I've been testing using port 80 and also port 9000. Any ideas on what I might be doing wrong? Thanks!

EDIT:

I changed my config file to look like the following

server {

  listen 9000;

  server_name _;

  location / {
    add_header Content-Type text/html;
    return 200 'test';
  }

I keep getting the same exact error. The firewall is turned off so it just seems like Nginx isn't listening on port 9000. Any ideas on why that might be the case?

1 comments

@Zenexer 2019-02-11 09:55:17

The most effective way would be to have three separate server directives, one for each port. That way, the upstream server isn't dynamic, so Nginx knows it can keep long-lived connections open to each one.

If you really don't want to do this, you might be able to get around it by doing something like this:

proxy_pass http://upstream_server.example:$server_port;

$port doesn't exist, but $server_port does, so that should work. (It's not $port because there are two ports for each connection: the server port and the client port, which are $server_port and $remote_port, respectively.)

@Bootsie123 2019-02-11 21:28:14

I set $port to $server_port at the top, I'll look into the separate server directives though.

Related Questions

Sponsored Content

2 Answered Questions

Keycloak Redirect url with nginx is going to http rather than https

  • 2018-04-03 12:02:15
  • Atulya Nair
  • 1097 View
  • 3 Score
  • 2 Answer
  • Tags:   nginx jboss

2 Answered Questions

[SOLVED] Nginx Not Port Listening when it runs as service

  • 2016-04-05 03:41:53
  • y0ngb00n
  • 599 View
  • 1 Score
  • 2 Answer
  • Tags:   nginx centos

0 Answered Questions

nginx docker compose redirect delay

2 Answered Questions

[SOLVED] Express - req.ip returns 127.0.0.1

1 Answered Questions

[SOLVED] Does Nginx support multiple ports forward with a single Jenkins instance?

0 Answered Questions

Passing a proxy for host before hitting URLs mentioned in Nginx/forward proxy

  • 2017-10-29 10:24:24
  • Alan
  • 29 View
  • 0 Score
  • 0 Answer
  • Tags:   nginx proxy

1 Answered Questions

Nginx win server 2012 - Configure proxy pass

  • 2017-07-31 15:02:09
  • johns193
  • 276 View
  • 0 Score
  • 1 Answer
  • Tags:   nginx proxy

2 Answered Questions

How to point many paths to proxy server in nginx

1 Answered Questions

Wordpress constant redirect with nginx upstream

2 Answered Questions

[SOLVED] nginx and trailing slash with proxy pass

Sponsored Content