Skip to content

Instantly share code, notes, and snippets.

@hamishforbes
Created February 28, 2014 13:43
Show Gist options
  • Save hamishforbes/9271324 to your computer and use it in GitHub Desktop.
Save hamishforbes/9271324 to your computer and use it in GitHub Desktop.
#push 404's to the matrix handler, this means static 404's in __data are handled by matrix too
error_page 404 = @matrix404;
#just serve data files
location /__data {
alias $matrix_root/data/public;
# Rewrite PHP files to matrix
location ~ asset_types/.*\.php$ {
expires off;
set $fcgi_script_name $request_uri;
rewrite ^(.*)$ /__matrix$1;
}
}
#fudge and lib contain some php scripts, annoying.
location /__fudge {
alias $matrix_root/fudge;
# Rewrite PHP files to matrix
location ~ \.php$ {
expires off;
set $fcgi_script_name $request_uri;
rewrite ^(.*)$ /__matrix$1;
}
}
location /__lib {
alias $matrix_root/core/lib;
# Rewrite PHP files to matrix
location ~ \.php$ {
expires off;
set $fcgi_script_name $request_uri;
rewrite ^(.*)$ /__matrix$1;
}
}
# Pass everything else to matrix handler
location / {
set $fcgi_script_name $document_root/core/web/index.php;
rewrite ^(.*)$ /__matrix$1;
}
location ~ .*/_edit {
set $fcgi_script_name $document_root/core/web/index.php;
rewrite ^(.*)$ /__matrix$1;
}
# deny .inc, .FFV and CVS
location ~ \.inc$ {
deny all;
}
location ~ /(CVS|\.FFV)/ {
deny all;
}
location @matrix404 {
set $fcgi_script_name $document_root/core/web/index.php;
rewrite ^(.*)$ /__matrix$1;
}
# This is an internal location that passes the 'current'
# request to matrix via lua-resty-fastcgi
location /__matrix {
lua_check_client_abort on;
internal;
rewrite ^/__matrix(.*) $1 break;
content_by_lua '
local ngx = ngx
local ngx_req = ngx.req
local ngx_var = ngx.var
local fcgi_host = ngx_var.fcgi_host;
local fcgi_port = ngx_var.fcgi_port;
local fcgi_connect_timeout = ngx_var.fcgi_connect_timeout;
local fcgi_read_timeout = ngx_var.fcgi_read_timeout;
local fcgi_index = ngx_var.fcgi_index;
local fcgi_script_name = ngx_var.fcgi_script_name;
local fcgic = fcgi.new()
local fastcgi_params = {
script_filename = fcgi_script_name .. ngx_var.request_uri,
}
ledge:config_set("fastcgi", fcgic)
ledge:config_set("fastcgi_params", fastcgi_params)
ledge:config_set("upstream_host", fcgi_host)
ledge:config_set("upstream_port", fcgi_port)
ledge:run()
';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment