nginx 配置 history

vue 打包到 nginx Uncaught SyntaxError: Unexpected token <

因为是history报此错误
官方配置history的解决方案:

location / {
  try_files $uri $uri/ /index.html;
}

其他方案:

location / {
            # 不缓存html,防止程序更新后缓存继续生效
            if ($request_filename ~* .*\.(?:htm|html)$) {
              add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
              access_log on;
            }
            root html/web;
            index  index.html index.htm;
            try_files $uri $uri/ @router; 
           }

        location @router{
            rewrite ^.+(?

注: 如此配置不行,并不是这两种方法是错误的, 就是路径不适合你root路径, 用本地nginx 或 docker 模拟环境 logo会报错路径错误,加以调试即可

你可能感兴趣的:(nginx 配置 history)