Skip to content

Instantly share code, notes, and snippets.

@sineld
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/9600197 to your computer and use it in GitHub Desktop.
Save sineld/9600197 to your computer and use it in GitHub Desktop.
Rewriting subdomains to the Document Root in Nginx
# http://www.nigeldunn.com/2011/06/30/rewriting-subdomains-to-the-document-root-in-nginx/
# hosts file: 127.0.0.1 proje.sineld.se proje2.sineld.se
server {
server_name ~^(.+)\.sineld\.se$;
set $file_path $1;
autoindex on;
autoindex_exact_size off;
root /home/sineld/www/$file_path/public_html;
error_log /var/log/nginx/$file_path-error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
index index.html index.php;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment