nginx配置

目录

location /

结论
1.proxy_pass代理地址端口后有目录(包括 / ),转发后地址:代理地址+访问URL目录+去除location匹配目录
2.proxy_pass代理地址端口后无任何,转发后地址:代理地址+访问URL目录+携带location配置的目录

  • location与proxy_pass都配置/,则不携带location配置的path
# www.test.com/api/upload-->http://127.0.0.1:8080/upload
location /api/ { proxy_pass http://127.0.0.1:8080/;
}
  • location不带/,proxy_pass带/,则真实地址会带/
# www.test.com/api/upload-->http://127.0.0.1:8080//upload
location /api { proxy_pass http://127.0.0.1:8080/;
}
  • location带/,proxy_pass不带/,则真实地址会带location匹配目录/api/
# www.test.com/api/upload-->http://127.0.0.1:8080/api/upload
location /api/ { proxy_pass http://127.0.0.1:8080;
}
  • location和proxy_pass都不带/,则真实地址会带location匹配目录/api/
# www.test.com/api/upload-->http://127.0.0.1:8080/api/upload
location /api { proxy_pass http://127.0.0.1:8080;
}
  • 同1,但 proxy_pass带地址
# www.test.com/api/upload-->http://127.0.0.1:8080/server/upload
location /api/ { proxy_pass http://127.0.0.1:8080/server/;
}

root | alias

alias是把location的值替换掉,而root是拼接上location的值。
假设文件在我们服务器的路径/img/1.jpg。

  • 当配置alias时
# 访问http://server_name/pic/1.jpg则能正常查看图片。
location /pic/ { alias /img/
}
  • 当配置root时
# 访问http://server_name/pic/img/1.jpg则能正常查看图片
location /pic/ { root /img/
}

vue history 404

  • 项目配置
location /{ root /website/wenfu_zszk/; index index.html; #解决404 try_files $uri $uri/ /index.html;
} location /kp { alias /usr/local/nginx/html/kp; index index.html; try_files $uri $uri/ /kp/index.html;
}
  • 正则项目配置
server { listen 80; server_name a; root /data/wwwroot/a; index index.html; location ~ /(\w+)/(\w+)/(\w+) { try_files $uri $uri/ /$1/$2/index.html; index /index.html; } access_log /data/logs/nginx/a_access.log; error_log /data/logs/nginx/a_error.log; }

NG日志日期

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") { set $year $1; set $month $2; set $day $3;
}
access_log /data/nginx/logs/myapp-$year-$month-$day-.access.log main; #windows归档脚本
@echo off
rem nginx rolling log
rem nginx workspace
set workspace=D:\software\nginx-1.20.2\nginx-1.20.2
echo "workspace:"%workspace%
rem logdir
set logdir=D:\logs\nginx
echo "logdir:"%logdir%
rem rename file
rem set datetime=%date:~0,4%_%date:~5,2%_%date:~8,2%
set datetime=%date:~10,4%_%date:~4,2%_%date:~7,2%
echo "datetime:"%datetime%
mkdir %logdir%\%datetime%
set targetdir=%logdir%\%datetime%
move %logdir%\uat-api-access.log %targetdir%\uat-api-access.log
move %logdir%\uat-api-error.log %targetdir%\uat-api-error.log
move %logdir%\uat-admin-access.log %targetdir%\uat-admin-access.log
move %logdir%\uat-admin-error.log %targetdir%\uat-admin-erro.log
move %logdir%\prd-api-access.log %targetdir%\prd-api-access.log
move %logdir%\prd-api-error.log %targetdir%\prd-api-error.log
move %logdir%\prd-admin-access.log %targetdir%\prd-admin-access.log
move %logdir%\prd-admin-error.log %targetdir%\prd-admin-error.log
rem reopen log
%workspace%\nginx.exe -s reopen -p %workspace%
rem del logs
rem set DaysAgo=10
rem forfiles /p %logdir% /m *.log /d -%DaysAgo% /c "cmd /c del /f /q @path"
rem pause 

©版权声明:本文为【翰林小院】(huhanlin.com)原创文章,转载时请注明出处!


©版权声明:本文为【翰林小院】(huhanlin.com)原创文章,转载时请注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注