A website uses nginx for load balancing and multiple nginx servers at the backend.
Encountered a problem, when it is used as SSL support, the front-end nginx is distributed to the back-end nginx and becomes an HTTP form (in this way, the backend PHP cannot be judged by $ _ server [HTTPS] = "on, but the backend must also know this parameter). If you change to https, you also need multiple certificates.
Therefore, we want the front-end nginx to pass a parameter to the backend if it is HTTPS. Used in the background for judgment and use.
First, use proxy_set_header in the nginx. conf file of the front-end nginx to set a parameter.UrlprefixThe value isHTTPS(It is recommended that you do not use underlines and hyphens for parameter names. The underlined parameters are ignored by nginx, while the underlined parameters are underlined by nginx, in order to avoid confusion, we simply don't need them. What should he do:
Location /{
Proxy_pass http: // myserver;
Proxy_set_header X-real-IP $ remote_addr;
Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
Proxy_set_header host $ http_host;
Proxy_set_header urlprefix HTTPS;
}
Enable the read header and set PHP parameters in the backend nginx server configuration.
Add underscores_in_headers on to the nginx. conf file;
Continue
You can use $ _ server ["..."] To set PHP parameters.
Location ~ \. Php $ {
Root htmll;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename/usr/local/nginx/html $ fastcgi_script_name;
Fastcgi_param url_prefix $ http_urlprefix;
Fastcgi_connect_timeout 300;
Include FastCGI. conf;
}
Explanation:
Fastcgi_param url_prefix $ http_urlprefix;(The parameter name set at the front end isUrlprefixHere, the read isHttp_urlprefixThis is because HTTP _ is added before all parameter names when nginx processes parameters. In additionFastcgi_param url_prefixThis parameter name is case sensitive and does not need to be prefixed during PHP reading .)
Then, the backend PHP can use $ _ server ['url _ prefix'] to obtain the parameters we set at the front end.
If (isset ($ _ server ['url _ prefix']) & $ _ server ['url _ prefix'] = "HTTPS "){
// Barabajara
}
Nginx Server Load balancer transmits the parameter method to the backend (the backend is also an nginx server)