Last active
August 29, 2015 13:57
-
-
Save sineld/9600197 to your computer and use it in GitHub Desktop.
Rewriting subdomains to the Document Root in Nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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