Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

映射和重定向规则

  • 特定开头路由 映射到 特定的ip和服务端口

    • 需要更改其中的 location
      location /xiaoeapi {
          proxy_pass https://127.0.0.1:7002;    
      }
      
  • 无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 的问题