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
- Install Nginx:
sudo apt update && sudo apt install nginx - Create a config in
/etc/nginx/sites-available/myapp:server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; } } - Enable the site:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/ - Test config:
sudo nginx -t - Reload Nginx:
sudo systemctl reload nginx
Tips
- Use
proxy_set_headerto pass original host and client IP information - For managing the Nginx service reliably, learn how to use systemd
- Restrict access with how to configure networking with iptables and ufw