问题描述
我正在使用 nginx-lua
模块与 redis
提供 ember的静态文件-app
。 索引
文件内容存储在 redis
中,作为值
当(root) domain / IP
被命中时,它正确地由 nginx
提供。
I am using nginx-lua
module with redis
to serve static files of ember-app
. The index
file content is stored in redis
as a value
which is being properly served by nginx
when the (root) domain/IP
is hit.
如果登录
页面是从链接打开的,它将被正确打开。但是当通过点击url栏或刷新页面直接打开时,nginx给出 404未找到
。
索引
文件位于 redis
中,其余文件由编译的 js
,它出现在 CDN
上。
以下是nginx配置
If login
page is open from link, it gets opened properly. But when opened directly by hitting the url bar or refreshing the page the nginx gives 404 not found
.The index
file is in redis
and rest of the files are being served from compiled js
which is present on a CDN
.Following is the nginx configuration
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配置可以找到。
Following nginx location block has to be added in order to serve the subroutes from index file being served from redis. A detailed explanation and full nginx config can be found 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;
}
这篇关于当网址从索引页面上的链接打开时,页面未找到404页面,但没有找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!