Skip to content
Follow
Ubuntu Linux

How to Setup Nginx Reverse Proxy

Richard
Written by
Richard
Oct 11, 2021 Updated Sep 15, 2026 2 min read
How to Display Seconds on Ubuntu Top Menu Clock
How to Display Seconds on Ubuntu Top Menu Clock

An Nginx reverse proxy acts as a traffic traffic cop between the internet and web apps running on your server, catching incoming requests on standard web ports like 443 and sending them to the right internal port.

Advertisement

Placing Nginx in front of web applications built with Node.js or Python handles encrypted HTTPS connections, blocks bad traffic, and passes clean requests straight to your app running on an internal port like 3000.

⚡ Quick Answer

Configure Nginx by defining a server block with a listen directive for the port and a location block. Inside the location block, use the proxy_pass directive to specify the backend server’s address. This setup directs incoming requests to your application.

Advertisement

How to use Nginx as a reverse proxy server

Setting up an Nginx reverse proxy setup involves routing your incoming web traffic from the front-facing server directly to your backend application. You do this by creating a specific server block in your configuration files that tells Nginx your app’s actual IP address and port number.

server {
    listen 80;
    server_name example.com;

    location /backend_app {
       proxy_pass http://127.0.0.1:8080;
    }
}
⚠️WarningThe configuration above tells Nginx to pass all requests to the /backdend_app location to the proxied server at http://127.0.0.1:8080.

Think of Nginx as a traffic director. It receives requests, like one for http://example.com/backend_app, and then sends that request to a specific backend server, such as one located at http://127.0.0.1:8080. Nginx performs this forwarding task using the `proxy_pass` instruction in its setup file.

Nginx proxy servers manage requests for many server types, not only web servers. For instance, Nginx proxy servers can handle requests for non-HTTP servers that use older protocols like FTP.

Advertisement
  • fastcgi_pass - reverse proxy to a FastCGI server.
  • uwsgi_pass - reverse proxy to a uwsgi server.
  • scgi_pass - reverse proxy to an SCGI server.

A common Nginx reverse proxy to non-HTTP hosts is done using PHP-FPM. An example is how Nginx serves PHP scripts.

Nginx reverse proxy settings manage web requests reaching backend applications. The `proxy_pass` setting directs traffic to specific servers. These Nginx reverse proxy settings ensure correct website functionality in 99% of setups.

 location/ {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version  1.1;
    proxy_cache_bypass  $http_upgrade;

    proxy_set_header Upgrade           $http_upgrade;
    proxy_set_header Connection        "upgrade";
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;
  }

For more advanced configurations or options suited to your specific environment, the official Nginx website is an excellent resource. This covers the basics of setting up Nginx as a reverse proxy.

Conclusion:

Advertisement

Configuring Nginx as a reverse proxy noticeably boosts the efficiency and performance of web applications.

  • Flexibility: Nginx can handle both HTTP and non-HTTP requests, making it suitable for various backend applications.
  • Efficiency: It offloads the processing from backend servers, managing tasks like SSL encryption and caching.
  • Scalability: Load balancing features help distribute client requests efficiently across multiple servers, improving performance.
  • Customizability: Nginx's configuration options allow you to tailor the reverse proxy settings to meet your specific needs.
  • Support for Modern Applications: Use Nginx with popular backend technologies like Node.js, Python, and PHP.

By following the basic configurations and using the options discussed, you can effectively implement Nginx as a reverse proxy in your environment.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

How to Setup WordPress Nginx Cloudflare Ubuntu Fast
CMS How to Setup WordPress Nginx Cloudflare Ubuntu Fast
How to Install Drupal with Nginx and Cloudflare on Ubuntu
CMS How to Install Drupal with Nginx and Cloudflare on Ubuntu
How to Setup Joomla on Ubuntu with Nginx & Cloudflare
CMS How to Setup Joomla on Ubuntu with Nginx & Cloudflare
How to Setup Magento with Nginx and Cloudflare on Ubuntu Linux
CMS How to Setup Magento with Nginx and Cloudflare on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *