2016-05-27 42 views
6

Sto usando il modulo nginx-lua con redis per servire file statici di ember-app. Il contenuto index file viene memorizzato in redis come value che viene adeguatamente servita da nginx quando il (root) domain/IP viene colpito.404 pagina non trovata quando viene urlato un url ma servito correttamente quando aperto dal collegamento nella pagina indice

Se login pagina è aperta da collegamento, diventa aperto correttamente. Ma quando aperto direttamente premendo la barra URL o aggiornare la pagina del nginx dà 404 not found. Il file index è in redis e resto dei file vengono servita dalle compilato js che è presente su un CDN. Segue la configurazione di 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) 

    '; 
} 
+0

Si usa il post e l'altro si ottiene mentre il server risponde solo a uno? – Randy

+0

@randy No, queste sono solo richieste GET. Come 'mydomain/login' quando viene aperto tramite un collegamento dalla pagina' index', viene visualizzato correttamente. Ma quando viene aperto premendo la barra dell'URL o aggiornando la pagina, mostra la '404 pagina non trovata ' –

risposta

4

seguente blocco posizione nginx è da aggiungere al fine di servire i subroutes da file di indice di essere servito da Redis. Una spiegazione dettagliata e la configurazione completa di nginx sono disponibili 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; 
    }