Skip to content

Instantly share code, notes, and snippets.

@xspager
Last active January 8, 2022 17:32
Show Gist options
  • Save xspager/2bc82d5d120de5e3e10e to your computer and use it in GitHub Desktop.
Save xspager/2bc82d5d120de5e3e10e to your computer and use it in GitHub Desktop.
##
#
# Sample config file for a Sailor based website
#
# On Debian you may copy this file to /etc/nginx/sites-available and then link it on /etc/nginx/sites-enabled
#
##
# Use the luarock's path command to get the value for those and add the path to your code for lua_package_path
lua_package_path '/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/share/lua/5.1//?.lua;/usr/share/lua/5.1//?/init.lua;./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/var/www/html/hey_arnold/?.lua';
lua_package_cpath '/usr/local/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so';
server {
listen 80 default_server;
## For IPv6
# listen [::]:80 default_server;
root /var/www/html/hey_arnold/; # where your site is
index index.lua; # if no path is expecified the URI will be /index.lua
server_name _;
location ~* ^.+\.(?:css|eot|js|json|png|svg|ttf|woff)$ { }
location ~ ^/(.+) {
lua_need_request_body on;
lua_code_cache off;
content_by_lua_file /var/www/html/hey_arnold/index.lua; # Path to index.lua inside your website
## the Lua code bellow will build the controller/action parameter from the user friendly URL
rewrite_by_lua '
-- if the request is NOT to the website index like http://example.com/
if ngx.var.uri ~= "/index.lua" then
local utils = require "web_utils.utils"
local path = utils.split(ngx.var.uri,[[/]])
local args = {}
local start
-- if both the controller and the action are expecified
if #path % 2 == 0 then
args[#args+1] = "r="..path[1]..[[/]]..path[2]
start = 3
else
args[#args+1] = "r="..path[1]
start = 2
end
for i=start,#path,2 do
args[#args+1] = path[i].."="..tostring(path[i+1])
end
ngx.req.set_uri_args(table.concat(args,"&"))
end
ngx.req.set_uri("/index.lua")
';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment