当开启反向代理以后,根目录的文件就无法访问了,这个时候可以使用这个技巧来实现。
当文件存在的时候,不走反向代理,直接返回;
当文件不存在的时候,正常走反向代理;
#PROXY-START/
location /{
try_files $uri @goproxy;
}
#反向代理
location @goproxy{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080;
# proxy_hide_header Upgrade;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
set $static_fileGQUxlfBU 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_fileGQUxlfBU 1;
expires 1m;
}
if ( $static_fileGQUxlfBU = 0 )
{
add_header Cache-Control no-cache;
}
}
#PROXY-END/
版权属于:大卫科技Blog
本文链接:https://www.iyuu.cn/archives/502/
转载时须注明出处