web_servers:nginx:setup_nginx_reverse_proxy
Differences
This shows you the differences between two versions of the page.
web_servers:nginx:setup_nginx_reverse_proxy [2021/10/13 16:31] โ created peter | web_servers:nginx:setup_nginx_reverse_proxy [2021/10/13 16:43] (current) โ peter | ||
---|---|---|---|
Line 25: | Line 25: | ||
</ | </ | ||
+ | ---- | ||
+ | |||
+ | ===== Disable the default virtual host ===== | ||
+ | |||
+ | <code bash> | ||
+ | unlink / | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Create a reverse proxy configuration file ===== | ||
+ | |||
+ | All of the settings for the reverse proxy will go inside of a configuration file, and this file needs be placed inside the **sites-available** directory. | ||
+ | |||
+ | <code bash> | ||
+ | cd / | ||
+ | </ | ||
+ | |||
+ | Create the configuration file: / | ||
+ | |||
+ | <file bash / | ||
+ | server { | ||
+ | listen 80; | ||
+ | location /some/path/ { | ||
+ | proxy_pass http:// | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * Replace example.com with the IP address or hostname of the server you are forwarding to. | ||
+ | * A port can also be specified with the hostname, such as 127.0.0.1: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Enable the proxy ===== | ||
+ | |||
+ | Enable the new configuring by creating a symbolic link to the **sites-enabled** directory: | ||
+ | |||
+ | <code bash> | ||
+ | ln -s / | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Proxy Non-HTTP servers ===== | ||
+ | |||
+ | Nginx can also act as a reverse proxy for FastCGI, uwsgi, SCGI, and memcached. | ||
+ | |||
+ | Rather than using the **proxy_pass** directive shown above, replace it with the appropriate type: | ||
+ | |||
+ | * **proxy_pass**: | ||
+ | * **fastcgi_pass**: | ||
+ | * **uwsgi_pass**: | ||
+ | * **scgi_pass**: | ||
+ | * **memcached_pass**: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Pass Headers ===== | ||
+ | |||
+ | To configure what headers the reverse proxy server passes to the other server(s), define them in the same / | ||
+ | |||
+ | Use the **proxy_set_header** directive to adjust the headers. | ||
+ | |||
+ | * They can be configured in the server, location, or http block. | ||
+ | |||
+ | <file bash / | ||
+ | location /some/path/ { | ||
+ | proxy_set_header HOST $host; | ||
+ | proxy_set_header X-Forwarded-Proto $scheme; | ||
+ | proxy_set_header X-Real-IP $remote_addr; | ||
+ | proxy_pass http:// | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * There are a lot of different options for passing headers. | ||
+ | |||
+ | * **Host**: | ||
+ | * **X-Forwarded-Proto**: | ||
+ | * **X-Real-IP**: | ||
+ | |||
+ | </ | ||
web_servers/nginx/setup_nginx_reverse_proxy.1634142664.txt.gz ยท Last modified: 2021/10/13 16:31 by peter