Skip to content

Instantly share code, notes, and snippets.

@hkoba
Last active December 18, 2015 01:39
Show Gist options
  • Save hkoba/5705004 to your computer and use it in GitHub Desktop.
Save hkoba/5705004 to your computer and use it in GitHub Desktop.
This way, like user_dir, you can host per-user fastcgi apps. Note: fcgi.sock must be readable by nginx. Usually, install -d -g nginx -m 2775 var/tmp is enough (If your nginx runs in nginx group).
# nginx_public_apps.conf
# http://example.com/-$USER-$APP_NAME/
# => /home/$USER/public_apps/apps/$APP_NAME/app/var/tmp/fcgi.sock
# Serve static files directly, with gzip_static.
location ~ ^/-(?<user>\w+?)-(?<app_name>[^/]+)/(?<static_fn>.*?\.(html|css|js|gif|jpg|png|ico|mp4|webm))$ {
set $app_root /home/$user/public_apps/apps/$app_name/app;
root $app_root/html;
try_files /$static_fn =404;
gzip_static on;
}
# anything else.
location ~ ^/-(?<user>\w+?)-(?<app_name>[^/]+)/(?<app_uri>.*)?$ {
set $app_root /home/$user/public_apps/apps/$app_name/app;
set $alias_root $app_root/html;
alias $alias_root;
fastcgi_pass unix:$app_root/var/tmp/fcgi.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $uri;
fastcgi_param SCRIPT_NAME ""; # For Plack::Handler::FCGI
fastcgi_param PATH_TRANSLATED $alias_root/$app_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment