加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx – 当网址被点击时找不到404页面,但是当从索引页面上的链

发布时间:2020-12-13 21:37:22 所属栏目:Nginx 来源:网络整理
导读:我正在使用带有redis的nginx-lua模块来提供ember-app的静态文件.索引文件内容存储在redis中,作为当(根)域/ IP被命中时由nginx正确提供的值. 如果登录页面是从链接打开的,则会正确打开.但是当通过点击url栏或刷新页面直接打开时,nginx会找不到404. 索引文件是

我正在使用带有redis的nginx-lua模块来提供ember-app的静态文件.索引文件内容存储在redis中,作为当(根)域/ IP被命中时由nginx正确提供的值.

如果登录页面是从链接打开的,则会正确打开.但是当通过点击url栏或刷新页面直接打开时,nginx会找不到404.
索引文件是redis,其余文件是从CDN上存在的已编译的js提供的.
以下是nginx配置

server
{
  listen 80 ;
  server_name 52.74.57.154;

  root /;

 default_type   text/html;
 location = / {
    try_files $uri $uri/ /index.html?/$request_uri;
    set_unescape_uri $key $arg_index_key;
    set $fullkey 'ember-deploy-cli:index:${key}';

     content_by_lua '
                local redis = require "resty.redis"
                local red = redis:new()

                red:set_timeout(1000) -- 1 sec



                local ok,err = red:connect("127.0.0.1",6379)
                if not ok then
                    ngx.say("failed to connect: ",err)
                    return
                end


        if ngx.var.key == "" then
            --ngx.say("No Argument passed")
            local res,err = red:get("ember-deploy-cli:index:current-content")
            ngx.say(res)
            return
        end
        local res,err = red:get(ngx.var.fullkey)

        if res == ngx.null then
            ngx.say("Key doesnt exist ")
            return
        end
        ngx.say(res)

     ';
 }
最佳答案
必须添加以下nginx位置块,以便从redis提供的索引文件中提供子路由.详细说明和完整的nginx配置可以找到here.

  # This block handles the subrequest. If any subroutes are requested than this rewrite the url to root and tries to render the subroute page by passing the subroute to index file (which is served by the redis).
  location ~* / {
  rewrite ^ / last;
  }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读