Nginx problem record (continuous update)

Keywords: Web Server Nginx

To record the Nginx problems encountered:

1. nginx is forwarded to other addresses because the proxy configured by default in the server layer_ set_ header Host $host;
Proxy needs to be configured in the location layer_ set_ header Host $proxy_ host;

location /xxx/ {
proxy_pass http://www.baidu.com/;
proxy_set_header Host $proxy_host;
}

2. Cross domain problem of nginx image

##Configure in location

location /xxx/ {
proxy_pass http://xxx:80/;

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
}

*3. Picture cross domain problem solving with cookie s, mainly 1. Add_ Header access control allow origin cannot be used
Main 2. add_header Access-Control-Allow-Credentials true;**

location /file/ {
proxy_pass http://xxxx:80/;
#Specifies that cross domain methods are allowed, * represents all
add_header Access-Control-Allow-Methods *;
#Check the cache of the command in advance. If not, the request will be sent twice at a time
add_header Access-Control-Max-Age 3600;
#This field needs to be added to the request with cookie and set to true
add_header Access-Control-Allow-Credentials true;
#Indicates that cross domain calls are allowed for this domain (domain name and port where the client sends the request)
#$http_origin the reason why the domain requested by the client is not * is that the request with cookie does not support * sign
add_header Access-Control-Allow-Origin $http_origin;
#Dynamic acquisition of fields representing request headers
add_header Access-Control-Allow-Headers
$http_access_control_request_headers;
#OPTIONS pre check command, send the request only when the pre check command passes
#Check whether the type of request is a pre check command
if ($request_method = OPTIONS){
return 204;
}
}

**4. Front end default jump to index.html It needs to be modified in nginx where the application is located,
You can't (temporarily find out what to do) forward processing in nginx, that is, you can't modify the following***

location /yytour/ {
proxy_pass http://xxxxxx:80/;
}

location ^~ /yytour/admin/ {
root /usr/share/nginx/html;
try_files $uri $uri/ /yytour/admin/index.html;
}

5. nginx forwarding configuration cache

location /xxxxx/ {
proxy_pass http://xxxxxx:80/;
if ($request_filename ~* ^.*?\.(htm|html)$){
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
expires -1;
}
if ($request_filename ~* ^.*?\.(gif|jpg|jpeg|png|bmp|swf)$){
expires 30d;
}
if ($request_filename ~* ^.*?\.(js|css)$){
expires 12h;
}
}

Posted by assafbe on Fri, 22 May 2020 08:50:50 -0700