server {
listen 80;
server_name mydomain.com;
location / {
proxy_pass http://myproxy.com:80;
proxy_set_header Host mydomain.com; #设置为跟server name 一样
}
}
As above, when proxy_set_header is set to the same as the server name, a 502 error occurs.
The error stack is as follows:
upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: mydomain.com, request: "GET /xx HTTP/1.0", upstream: "http://127.0.0.1:80/ xx", host: "mydomain.com
I am puzzled, what could be the reason for this?
When I update the proxy port, such as changing it from 80 to 81 proxy_pass http://myproxy.com:81;
At this point, it can work normally. (My previous myproxy.com was listen 80. Now it is changed to 81.)
But why ?
Your upstream is gone
CentOS7 installation and maintenance of Nginx, common usage scenarios
or this form