【问题标题】:how to make nginx work with html5mode and images如何使 nginx 与 html5mode 和图像一起工作
【发布时间】:2017-08-13 11:49:17
【问题描述】:

我一直在谷歌搜索如何使用 nginx 为 Angular 应用程序启用 html5。 我发现的大多数帖子都推荐使用

try_files $uri $uri/ /index.html =404;

我一直在运行一些测试,并且导航似乎一切正常。

除非我插入具有有效路径的图像,否则它可以正常工作 但是如果我插入一个路径无效的图像,它会返回 200 而不是 404。 或者如果我尝试。

try_files $uri $uri/ /index.html=404;

当插入带有无效路径的图像时,它会返回 500 而不是 404。

如何只为路由启用 html5 模式,而不影响图像?

【问题讨论】:

    标签: angularjs nginx html5mode


    【解决方案1】:

    通过为资产添加新的定位路线解决了这个问题

    location ~* \.(?:ico|gif|jpe?g|png)$ {
          try_files $uri =404;
        }
    

    感谢@szarapka 给我答案

    https://gist.github.com/szarapka/05ba804dfd1c10ad47bf

    【讨论】:

      猜你喜欢
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 2013-11-12
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2019-09-08
      相关资源
      最近更新 更多