try_files踩坑记录


server {
    listen       80;
    server_name  test-h5.qc.vip;
    #http重定向到https
    rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen       443 ssl;
    server_name  test-h5.qc.vip;
    #root 配合try_files使用
    root         /opt/www;
    # 重定向 404 403
    error_page   404 403 = https://www.cnblogs.com/nightOfStreet/;

    # app -> 活动页
    # 如果try_files前面2个变量都没找到,会直接重定向第三个变量到root + /h5/index.html
    location ^~ /app {
        alias /opt/www/h5;
        try_files $uri $uri/ /h5/index.html;
    }

    # mall -> 商场
    # alias 会移除匹配字符,将匹配到的路径加在alias路径后 https://test-h5.qc.vip/mall/pages/index ->/opt/www/mall + /pages/index
    location ^~ /mall {
        alias /opt/www/mall;
        try_files $uri $uri/ /mall/index.html;
    }
    add_header Cache-control no-store;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM