【问题标题】:Nginx try_files redirect not serving css/imagesNginx try_files 重定向不提供 css/图像
【发布时间】:2016-12-28 19:30:41
【问题描述】:

我正在尝试将https://example.com/user/whatever 下的所有请求重定向到我的“获取我们的应用程序”页面,地址为https://example.com/get_app.html

在我的 nginx.conf 中,我有以下块设置:

#Redirect all requests under /user/ to the "get App" page
  location /user/ {
    try_files $uri $uri/ /get_app.html;
  }

提供了 html 文件,但未显示 css 和图像。只是一个带有我的 html 的纯白页面。如果我只输入example.com/user/whatever,页面就会正确提供。我究竟做错了什么?为什么来自重定向时 nginx 不能正确地提供文件?

【问题讨论】:

    标签: html css nginx configuration


    【解决方案1】:

    最后把我的配置写成:

    location /user/ {
       return 301 https://example.com/get_app.html;
    }
    

    因为使用 try_files 试图从 example.com/user/whatever/css/ 获取 css 而我不知道如何解决这个问题。上面的重定向应该足以满足我想要实现的目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      • 2012-09-21
      • 1970-01-01
      相关资源
      最近更新 更多