Proxying to your app running on custom port in NGINX

Proxying to your app running on custom port in NGINX

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

More than ever, if you're managing a server either as an EC2 instance on AWS, or as a VM instance on GCP, or just working on your local machines, proxying to your app's custom port comes in handy if:

  • Your app uses a protocol other than HTTP/HTTPS
  • You are working towards balancing the load across multiple containers
  • You want to test new features as canary deployments
  • and so on...

Here's a quick .conf snippet to proxy pass a request coming on port 80 to port 8081 where your custom app is running:

server {
    listen 80;
    access_log /path/to/log/access.log;
    error_log /path/to/log/error.log;

    location / {
        proxy_pass http://localhost:8081;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;

Of course, you can replace the ports with your own values.

Share this



This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organisations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Any views or opinions are not intended to malign any religion, ethnic group, club, organisation, company, or individual.

The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.

Downloadable Files and Images

Any downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.


Comments are welcome. However, the blog owner reserves the right to delete any comments submitted to this blog without notice due to:

  • Comments deemed to be spam or questionable spam.

  • Comments including profanity.

  • Comments containing language or concepts that could be deemed offensive.

  • Comments containing hate speech, credible threats, or direct attacks on an individual or group.

The blog owner is not responsible for the content in comments.

This blog disclaimer is subject to change at anytime.

Proudly part of