I solved this problem on the first morning of work in the new year. To be honest, it was the first time I encountered it. Using a domain name to proxy a web project, when requesting, the domain name is not used for some reason, but the IP port is directly used as the path, causing the web page to crash and become unusable.
Because nginx is used as the front-end server, I made some modifications. The following is the comparison before and after the modification:
Before modification:
server {
80; .aaaaa " proxy_set_header X-Real-IP $remote_addr;
index index.html index .htm ; }
Modified: server { 80; server_name xxx.aaaaa.com; location / { proxy_pass http://10.148.2
2
.8
1
:8180;
proxy_read_timeout 600s;
proxy_set_header $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; index index.html index.htm; 02 503 504 /50x.html;
location = /50x.html { root html;
}
} 访 The visit is successful.
Of course it is recommended that for static resources, use for example
location ~ .*.(gif|jpg|png|html|htm|css|js|flv|ico|swf)(.*) { proxy_redirect off; proxy_set_header Host $host; proxy_cache cache_one; proxy_cache_valid 200 302 1h;
proxy_cache_valid any 1m;
expires 30d;
’ ’ ’ ’s ’ ’ s ’ through ’ ‐ ‐ ‐‐ ‐‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ 1m;
The main reference is the original text. I am very grateful to this big brother for his guidance:
http://www.cnblogs.com/likehua/p/4056625.html
The content is as follows:
The default reverse port of Nginx is 80, so there is a problem that the port after being proxied is 80, which leads to access errors. The main reason is that the response port is not set in the host configuration of the Nginx configuration file.
The relevant configuration files are as follows:
1
2
34
proxy_pass http://ime-server/ime-server;
proxy_set_header Host $host;
As above, the Host configuration only has host and no corresponding port, which results in obtaining the wrong port at the place being proxied. This article takes java as an example:
At this time, the obtained port is 80, although the port nginx listens to is 9090. This error makes me very depressed. Therefore, modify the nginx configuration file and change the value after Host to $host:$server_port. The configuration file is as follows: