Nginx can be easily configured to work as a reverse proxy:
location /example { proxy_pass http://upstream_server_name; }
In the preceding code, upstream_server_name
is the host name of the upstream server. When a request for location is received, it will be passed to the upstream server with a specified host name.
If the upstream server does not have a host name, an IP address can be used instead:
location /example { proxy_pass http://192.168.0.1; }
If the upstream server is listening on a nonstandard port, the port can be added to the destination URL:
location /example { proxy_pass http://192.168.0.1:8080; }
The destination URL in the preceding examples does not have a path. This makes Nginx pass the request as is, without rewriting the path in the original request.
If a path is specified in the destination URL, it will replace a part of the path from the original request that corresponds to the matching part of the location. For example, consider...