Skip to content

Use Nginx as forwarding proxy

Using Nginx as a reverse proxy is very simple. Here are the steps to use Nginx as a reverse proxy:

Step 1

Install Nginx: First, make sure Nginx is installed on your system. You can install Nginx using package managers like apt, yum, or brew.

Step 2

Configure Nginx: Open the Nginx configuration file (usually located at /etc/nginx/nginx.conf) and make the following changes:

a. Add the following content within the http block:

http {
    server {
        listen 8888;  // Set the port number on which the proxy server listens
        resolver 8.8.8.8;  // Set the DNS resolver
        location / {
            proxy_pass http://$http_host$request_uri;  // Set the target address for proxy forwarding
        }
    }
}

b. Save and close the configuration file.

Step 3

Start Nginx: Start the Nginx service using the appropriate command. For example, use the following command to start Nginx:

sudo nginx -t
sudo systemctl nginx restart

Step 4

Configure the client: Configure the following settings on the client that needs to use the proxy:

  1. Open the network settings or browser settings.
  2. Find the proxy settings and set the proxy server address to the IP address and port number of your Nginx server (e.g., 192.168.0.1:8888).
  3. Save the settings and close the window.

Now you have successfully configured Nginx as a reverse proxy. When a client makes a request, Nginx will receive the request and forward it to the target server. Make sure the Nginx server has internet access and the client can communicate with the Nginx server.

Please note that this is just a basic configuration example. You can perform more advanced configurations according to your needs, such as adding authentication, caching, and other functionalities. For more detailed information, please refer to the official documentation of Nginx.

Reference

  • https://stackoverflow.com/questions/46060028/how-to-use-nginx-as-forward-proxy-for-any-requested-location
  • https://www.baeldung.com/nginx-forward-proxy
  • https://www.alibabacloud.com/blog/how-to-use-nginx-as-an-https-forward-proxy-server_595799
  • https://superuser.com/questions/604352/nginx-as-forward-proxy-for-https
  • https://www.reddit.com/r/nginx/comments/uay8i1/nginx_as_a_forward_proxy/
Leave a message