Nginx Address Forwarding Setup Guide
Configuring address forwarding in nginx can be achieved by setting up the server block. Here’s a simple example:
- Open the configuration file for nginx, which is usually named nginx.conf.
- Add a server block in the HTTP block as shown below:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend_server;
}
}
In the example above, when a user accesses example.com, nginx will forward the request to the backend server.
- To set up the address and port of the backend server, you can add an upstream block in the nginx.conf file to define the address and port of the backend server, as shown below:
upstream backend_server {
server backend_ip:port;
}
The backend_ip is the IP address of the backend server, and port is the port number.
- Save and close the configuration file, reload the nginx configuration or restart the nginx service to apply the changes.
By following the above steps, you can configure address forwarding in nginx to implement request forwarding.