当网址被点击时,找不到404页面,但是当从索引页面上的链接打开时正确提供了该页面

dri*_*uja 6 lua nginx ember.js

我正在使用nginx-lua模块redis来提供静态文件ember-app.index文件内容存储redis为在(根)被命中时value正确提供的文件内容.nginxdomain/IP

如果login页面从链接打开,它将正确打开.但是当通过点击url栏直接打开或刷新nginx提供的页面时404 not found.该index文件位于其中redis,其余文件正在编译js中提供,该文件存在于a上CDN.以下是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)

     ';
 }
Run Code Online (Sandbox Code Playgroud)

Aje*_*han 4

必须添加以下 nginx 位置块,以便为 Redis 提供的索引文件中的子路由提供服务。详细的解释和完整的 nginx 配置可以在这里找到。

  # 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;
  }
Run Code Online (Sandbox Code Playgroud)