How to set up an Nginx reverse proxy on Linux

· Category: Linux

Short answer

Install Nginx, create a server block with proxy_pass, and reload the service. A reverse proxy forwards client requests to backend servers. For securing the server with a firewall, see how to configure networking with iptables and ufw. For DNS configuration, see how to configure DNS on Linux.

Steps

  1. Install Nginx: sudo apt update && sudo apt install nginx
  2. Create a config in /etc/nginx/sites-available/myapp: server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; } }
  3. Enable the site: sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
  4. Test config: sudo nginx -t
  5. Reload Nginx: sudo systemctl reload nginx

Tips