User Tools

Site Tools


web_servers:nginx:setup_nginx_reverse_proxy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

web_servers:nginx:setup_nginx_reverse_proxy [2021/10/13 16:31] โ€“ created peterweb_servers:nginx:setup_nginx_reverse_proxy [2021/10/13 16:43] (current) โ€“ peter
Line 25: Line 25:
 </code> </code>
  
 +----
 +
 +===== Disable the default virtual host =====
 +
 +<code bash>
 +unlink /etc/nginx/sites-enabled/default
 +</code>
 +
 +----
 +
 +===== 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 /etc/nginx/sites-available
 +</code>
 +
 +Create the configuration file:  /etc/nginx/sites-available/reverse-proxy.conf
 +
 +<file bash /etc/nginx/sites-available/reverse-proxy.conf>
 +server {
 +    listen 80;
 +    location /some/path/ {
 +        proxy_pass http://example.com;
 +    }
 +}
 +</file>
 +
 +<WRAP info>
 +**NOTE:**  This will work for HTTP servers, but Nginx also supports other protocols.
 +
 +  * 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:8080.
 +
 +</WRAP>
 +
 +----
 +
 +===== Enable the proxy =====
 +
 +Enable the new configuring by creating a symbolic link to the **sites-enabled** directory:
 +
 +<code bash>
 +ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
 +</code>
 +
 +----
 +
 +===== 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**: (HTTP server โ€“ as seen above)
 +  * **fastcgi_pass**:  FastCGI server.
 +  * **uwsgi_pass**:   uwsgi server.
 +  * **scgi_pass**:   SCGI server.
 +  * **memcached_pass**:  Mmemcached server.
 +
 +----
 +
 +===== Pass Headers =====
 +
 +To configure what headers the reverse proxy server passes to the other server(s), define them in the same /etc/nginx/sites-available/reverse-proxy.conf configuration file.
 +
 +Use the **proxy_set_header** directive to adjust the headers.
 +
 +  * They can be configured in the server, location, or http block.
 +
 +<file bash /etc/nginx/sites-available/reverse-proxy.conf>
 +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://example.com;
 +}
 +</file>
 +
 +<WRAP info>
 +**NOTE:**  This defines three types of headers and sets them to the respective variables.
 +
 +  * There are a lot of different options for passing headers.
 +
 +  * **Host**:  contains information about which host is being requested.
 +  * **X-Forwarded-Proto**:  species if the request is HTTP or HTTPS.
 +  * **X-Real-IP**:  contains the IP address of the requesting client.
 +
 +</WRAP>
  
web_servers/nginx/setup_nginx_reverse_proxy.1634142664.txt.gz ยท Last modified: 2021/10/13 16:31 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki