nginx - 命中 url 时找不到 404 页面,但从索引页面上的链接打开时正确提供

标签 nginx ember.js lua

我正在使用 nginx-lua带有 redis 的模块提供 ember-app 的静态文件. index文件内容存储在redis作为 valuenginx 正确提供服务当(根)domain/IP被击中。

如果 login页面从链接打开,它被正确打开。但是当通过点击 url 栏或刷新页面直接打开时,nginx 会给出 404 not found .index文件位于 redis其余文件由编译后的 js 提供存在于 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)

     ';
 }

最佳答案

必须添加以下 nginx 位置 block ,以便为从 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;
  }

关于nginx - 命中 url 时找不到 404 页面,但从索引页面上的链接打开时正确提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37480357/

相关文章:

ubuntu - Nginx: "/var/www/html/"的 28 目录索引被禁止,

nginx - 使用Nginx的Elasticsearch基本身份验证

Ember.js 将现有记录克隆到存储中

c - Lua 库中奇怪的 C 语法

oop - 函数如何进入 Lua 中的表?

nginx - 如何匹配Nginx中的所有位置以进行身份​​验证?

基于主机名的 Nginx TCP 转发

javascript - 在 Ember 的动态路由上使用非持久记录的正确方法是什么

ember.js - 在 Ember.Route 上使用 setupController 时需要在 Controller 上设置模型吗?

search - Lua中如何在另一个表的表成员中搜索