1. Troubleshooting and locating the problem of Nginx returning 404 after configuring proxy_pass1.1. Problem In a production configuration involving multiple forwardings, the requirement is the following diagram: 1.2. Find the cause of the problem Our default Nginx proxy_set_header Host $host;
When we use this setting, when the first layer of Nginx (Nginx1) is proxying, the domain name we request is www.djx.com, and the host value obtained from the header of this request is proxy_set_header Host $host; The host value is set to the forwarded Host value, but the requested domain name is 1.3. proxy_set_header official informationOfficial Documentation The default setting is proxy_set_header Host $proxy_host; proxy_set_header Connection close; 1.4 Solution The value of Host is set to proxy_set_header Host $proxy_host; 2. Expanding Common Configurations1. $proxy_hostproxy_set_header Host $proxy_host; #Default configuration# As the name implies, the request header is set to the domain name behind the proxy. Example 1: upstream open-hz8443{ server 10.60.6.184:8000 max_fails=1 fail_timeout=3s weight=10; } Then the value of $proxy_host here is open-hz8443. Example 2: location ^~ /wss/v1 { proxy_pass http://10.60.6.184:8000; proxy_set_header Host $proxy_host; proxy_set_header Connection "upgrade"; proxy_set_header Upgrade $http_upgrade; tcp_nodelay on; } 2. $hostproxy_set_header Host $host; # When the field is not in the request header, it cannot be passed. In this case, you can assign the value to the Host variable by setting the Host variable. When there is no Host value in the request header, the value of server_name is directly used to fill it. When the Host value in the request header is received, the Host value in the request header is directly used. 3. $host:$proxy_port proxy_set_header Host $host:$proxy_port; # The server name and port are passed together through the proxy server. Compared with the previous item, there is an additional $proxy_port. This $proxy_port is the port in proxy_pass. If there is no port, such as 80 and 443. It will also use 80/443 filling. Example: proxy_pass http://www.baidu.com; $host:$proxy_port = Baidu ip:80 4. $http_hostproxy_set_header Host $http_host; # A non-changing "Host" request header field can be passed as follows: When there is no Host value in the request header, the value of server_name is directly used to fill it. And add the port. If it is 80/443, do not add it. In fact, it is to request the value in the url. When the Host value in the request header is received, the Host value in the request header is directly used. Example
Basic Configuration server{ listen 80; server_name www.djx.com; location / { proxy_pass http://www.baidu.com/; } } 192.168.1.190 Nginx2 server{ listen 80; server_name www.baidu.com; location / { proxy_pass http://192.168.1.80:8080/; } } ** Using Basic Configuration ** proxy_set_header Host $proxy_host; Then the value of the header to http://192.168.1.80:8080/ is www.baidu.com. ** Using $host ** proxy_set_header Host $host; Reference article: https://cloud.tencent.com/developer/article/1557504 This is the end of this article about the 404 error after Nginx configuration proxy_pass. For more relevant content about Nginx configuration proxy_pass, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: HTML form tag tutorial (5): text field tag
>>: Practical tutorial on modifying MySQL character set
There are three ways to interconnect and communic...
The question is referenced from: https://www.zhih...
Table of contents premise TypeScript vs JavaScrip...
Docker installation (Alibaba Cloud Server) Docker...
Use vite to build a vue3 project You can quickly ...
Preface Believe me, as long as you remember the 7...
This article example shares the specific code of ...
What is a selector? The role of the selector is t...
I was recently writing a lawyer recommendation we...
There are few and inadequate installation tutoria...
Table of contents 1. Build Docker 2. Enter the co...
Awk is a powerful tool that can perform some task...
An event is an action performed by the user or th...
1. Yum installation yum install subversion 2. Con...
System environment: centos7.4 1. Check whether th...