With HTTP keepalive enabled in NGINX upstream servers reduces latency thus improves performance and it reduces the possibility that the NGINX runs out of ephemeral ports. Following the suggestion given by NGINX doc that the proxy_http_version directive should be set to "1.1" and the "Connection" header field should be cleared:
upstream backend {
server 127.0.0.1:8080;
keepalive 16;
}
server {
listen 80;
server_name www.webfoobar.com;
root /var/www/html;
location /http/ {
proxy_pass http://backend/index.php?q=$uri;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
With this NGINX configuration, it serves wrong URL and content. It redirects the http://www.webfoobar.com to http://backend/index.php?q=/.
To solve this, add proxy_set_header directive in NGINX configuration to set the 'Host' header to the value in the client request or primary server name:
upstream backend {
server 127.0.0.1:8080;
keepalive 16;
}
server {
listen 80;
server_name www.webfoobar.com;
root /var/www/html;
location /http/ {
proxy_pass http://backend/index.php?q=$uri;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
}
}
Comments
You're welcome. I'm glad it…
You're welcome. I'm glad it help you.
谢谢楼主,这个配置很有效!
谢谢楼主,这个配置很有效!
You're welcome
You're welcome. I'm glad this article helped.
thanks
Thank YOU SO MUCH!
I have been experimenting this one, as documentation did not tell anything about it, but telling disabling connection header..... I was debugging so I saw that bugged host...
You bring me the solution... thanks!