Table of Contents

Nginx - Proxy

About

proxy in Nginx

Example

A proxy is defined in a location block

upstream targetService {
    server 127.0.0.1:8080;
    # A keepalive directive sets the maximum number of upstream idle connections that can remain open at any given time (for each Nginx worker process).
    keepalive 64;
}

location / {

	proxy_set_header X-Forwarded-Host $host;
	proxy_set_header X-Forwarded-Server $host;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-Proto "https";
	proxy_pass http://targetService;
	proxy_http_version 1.1;
	proxy_pass_request_headers on;
	proxy_set_header Connection "keep-alive";
	proxy_store off;

}

where:

Proxy Pass

If the URI is specified along with the address, it replaces the part of the request URI that matches the location parameter.

For example, with the below configuration:

location /some/path/ {
    proxy_pass http://www.example.com/link/; # the end slash is important
}