nginx 配置 vue History模式

解决

需要加一行 try_files $uri $uri/ /index.html;,其中 /index.html 是你自己的目录中的入口文件

复制代码
server {
        listen [::]:80 default_server;

        #root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                root /root/test/dist;
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.html;
        }
……
}
复制代码
try_files file... uri

这个语法的意思是:

  • try_files 后面可以定义多个文件路径和最后一个作为内部跳转的 uri,其中文件路径是和 aliasroot 两个指令合在一起构造而成
  • 多个文件以第一个找到的文件作为请求;
  • 而文件后面以"/"结尾,会检查目录是否存在;
  • 当文件都找不到时,就会去以最后一个uri进行内部跳转请求
posted @   牛奔  阅读(461)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-05-28 go map fatal error: concurrent map iteration and map write 读写锁与深度拷贝的坑
2021-05-28 vue 判断某个时间小于当前时间
2021-05-28 elmentui input number 数字验证
2019-05-28 HTTP与HTTPS的区别
点击右上角即可分享
微信分享提示