Wednesday, January 26, 2011

Nginx Config: Front-End Reverse Proxy to Another Port

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.

  • 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!

    Ted Karmel : Thanks this was just what I was looking for...
    From vmfarms
  • 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/;
    
            }
        }
    }
    
    Ted Karmel : Tyler - your minimal solution is good. That's what I wanted. Would give you points if I could but still new on serverfault
    From tylerl

0 comments:

Post a Comment