How to Set Up an NGINX Reverse Proxy
2 min read
1 year ago
Published on Apr 24, 2024
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
How to Set Up an NGINX Reverse Proxy
NGINX is a powerful web server that can also be used as a reverse proxy. In this tutorial, we will walk through the steps to set up an NGINX reverse proxy to proxy traffic to another application running on a different port.
Step 1: Connect to Your Linode
- Connect to your Linode using SSH.
- Install NGINX by running the command:
sudo apt install nginx
.
Step 2: Install NGINX Mainline Version
- Download the NGINX signing key by running:
wget <url_to_signing_key>
. - Add the key to your Linode by running:
sudo apt-key add <key_filename>
. - Edit the NGINX repository file by opening it with a text editor:
sudo nano /etc/apt/sources.list.d/nginx.list
. - Add the repository for your Ubuntu version (e.g., focal for Ubuntu 20.04).
- Update the repository index by running:
sudo apt update
.
Step 3: Start NGINX
- Start NGINX by running:
sudo systemctl start nginx
. - Enable NGINX to start on boot by running:
sudo systemctl enable nginx
.
Step 4: Configure NGINX Reverse Proxy
- Create a new configuration file for your proxy by running:
sudo nano /etc/nginx/conf.d/nodeapp.conf
. - Paste the configuration code into the file. Replace
example.com
with your domain name or IP address. - Save and exit the editor.
- Test the NGINX configuration for syntax errors by running:
sudo nginx -t
. - If the test is successful, reload NGINX to apply the new configuration:
sudo systemctl reload nginx
.
Step 5: Run Your Application
- Start your application (e.g., a Node.js app) on the designated port (e.g., port 3000).
- Access your application through the NGINX reverse proxy by entering your Linode's IP address in a web browser.
Step 6: Additional Steps (Optional)
- Secure your application with an SSL certificate using Certbot.
- Explore other use cases for NGINX as a reverse proxy for different applications.
By following these steps, you can successfully set up an NGINX reverse proxy to proxy traffic to your application running on a different port.