How to set up an NGINX reverse proxy
The steps to set up Nginx reverse proxy are as follows:
- To install Nginx, first you need to install it on the server, which can be done using a package manager like apt or yum.
- Edit the Nginx configuration file, which is typically located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf. Open the file using a text editor.
- Set up reverse proxy
Locate the server block in the configuration file and add multiple server blocks as needed. In each server block, configure the proxy_pass directive to set the target address for the reverse proxy. - For example, the following configuration proxies all requests from localhost:8080 to the target address http://example.com:
- The server is configured to listen on port 80 and respond to requests with the hostname localhost. Any requests to the root URL will be proxied to http://example.com.
- Additional configurations can be made based on specific needs, such as setting proxy paths and adding request headers.
- Save and exit the configuration file
After completing the configuration, save and exit the Nginx configuration file. - Restart the Nginx service by using the appropriate command to apply the configuration changes.
Once configured, Nginx will forward all requests from the specified port to the target address and return the response to the client.