Skip to content

Instantly share code, notes, and snippets.

@dorentus
Created December 12, 2013 09:07
Show Gist options
  • Save dorentus/7925121 to your computer and use it in GitHub Desktop.
Save dorentus/7925121 to your computer and use it in GitHub Desktop.
NGINX configurations
#
# $BASE_DIR = case $http_host
# when "a.example.com"
# "a.example.com"
# when "a.b.example.com"
# "b.example.com"
# end
#
set $BASE_DIR $http_host;
if ($http_host ~* ^([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+)$) {
set $BASE_DIR $2;
}
# server bound to unix socket: tmp/sockets/web.sock
location @server {
error_log off;
error_page 502 504 = @fallback_php;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Client-Verify $ssl_client_verify;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_set_header X-SPDY $spdy;
proxy_redirect off;
proxy_pass http://unix:/var/opt/sites/$BASE_DIR/tmp/sockets/web.sock;
}
# try index.php
location @fallback_php {
rewrite ^(.*)$ /index.php/$1 last;
}
# PHP (seperated fastcgi process, bound to tmp/sockets/php.sock)
location ~ index\.php {
root /var/opt/sites/$BASE_DIR/php;
if ( !-f $document_root$fastcgi_script_name ) {
return 404;
}
fastcgi_pass unix:/var/opt/sites/$BASE_DIR/tmp/sockets/php.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
# web root dir: public
location / {
root /var/opt/sites/$BASE_DIR/public;
try_files $uri $uri/index.htm $uri/index.html @server;
}
server {
listen 80 default_server;
server_name _;
return 444;
}
server {
listen 80;
server_name *.tomodachi.name *.madokami.info;
access_log off;
include /etc/nginx/include.d/common-basedir;
include /etc/nginx/include.d/common-server;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment