33

I have a small web server that serves requests on port 5010 rather than 80.

I would like to use nginx as a front end proxy to receive requests on port 80 and then let those requests be handle by port 5010.

I have installed nginx successfully and it runs smoothly on Ubuntu Karmic.

But, my attempts to reconfigure the default nginx.conf have not been successful.

I tried including in the server directive the listen argument for port 5010.

I have also tried proxy_pass directive.

Any suggestions on changes that need to be made or directives that need to be set in order to just have port forwarding.

2 Answers 2

28

I'm assuming that nginx is not the server listening on port 5010 as well as 80, correct? Something else is listening on 5010 and you wish to have nginx proxy to that server?

If that's the case, here's a nice sample config I've used in the past with success:

server {
        listen       80;
        server_name  <YOUR_HOSTNAME>;
        location / {
            proxy_pass         http://127.0.0.1:5010/;
            proxy_redirect     off;

            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;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }
}

I believe that should accomplish what you're seeking. Good luck!

1
  • this does not work on macOS brew nginx. You have to add a http {} block surrounding server, otherwise: nginx: [emerg] "server" directive is not allowed here
    – muenalan
    Jul 20, 2018 at 10:57
24

Pretty minimalist -- I've left the proxy settings as default, though you may want to look in to it to adjust to your needs.

# NGINX configuration

# System configuration ##################
worker_processes  3;
events {
    worker_connections  1024;
}
user nobody;

# Web configuration #####################
http {
    server {
        listen 80 default;
        location / {
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   Host             $host;

            proxy_pass http://127.0.0.1:5010/;

        }
    }
}
2
  • 2
    Tyler - your minimal solution is good. That's what I wanted. Would give you points if I could but still new on serverfault
    – Ted Karmel
    Aug 18, 2010 at 13:01
  • 2
    What of your configuration is mandatory? I've not set worker_connections , worker_processes, _user and the headers and my port is 81. The rest is the same. I get a 502 (Bad Gateway).
    – Alex 75
    Jul 25, 2022 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .