映射和重定向规则
-
把
特定开头路由映射到特定的ip和服务端口上- 需要更改其中的 location
location /xiaoeapi { proxy_pass https://127.0.0.1:7002; }
- 需要更改其中的 location
-
把
无www访问重定向到www.上- 需要添加一个
https项目
server{ listen 443; server_name fastcats.top; return 301 https://www.fastcats.top$request_uri; } - 需要添加一个
-
把
http访问重定向到https上- 需要修改原有的
http项目,在最后加入一行server { listen 80; server_name www.fastcats.top; return 301 https://$server_name$request_uri; }- 千万别把uri写成url
- 需要修改原有的
-
对于前端项目(放在xxx文件夹内),可以参考以下location配置
- 需要更改其中的 location
location /xxx{ alias /opt/www/xxx; try_files $uri $uri/ /index.html last; } - 能解决 配置history模式 的问题
- 里面alias和last 能解决 页面刷新后404 的问题
- 需要更改其中的 location