我正在使用 nginx-lua
带有 redis
的模块提供 ember-app
的静态文件. index
文件内容存储在redis
作为 value
由 nginx
正确提供服务当(根)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/