Created
August 7, 2016 09:04
-
-
Save amekusa/a4100d8253b049277f2bfa1ea7055841 to your computer and use it in GitHub Desktop.
Dynamic Virtual Hosts
This file contains hidden or 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
| server { | |
| listen 80; | |
| # listen on the www host | |
| server_name ~^(www\.)(?<domain>.+)$; | |
| # and redirect to the non-www host (declared below) | |
| return 301 $scheme://$domain$request_uri; | |
| } | |
| server { | |
| listen 80; | |
| # catch all non-www domains | |
| server_name ~(?<domain>.+)$; | |
| set $base /srv/http; | |
| root $base/$domain/www; | |
| index index.html index.htm index.php; | |
| access_log /var/log/nginx/server.$domain.access.log; | |
| error_log /var/log/nginx/server.$domain.error.log; | |
| # check file exist and send request string to index.php | |
| location / { | |
| try_files $uri $uri/ /index.php?$args; | |
| } | |
| location ~ \.php$ { | |
| try_files $uri =404; | |
| fastcgi_pass "unix:/var/run/php-fpm/php-fpm.sock"; | |
| fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
| fastcgi_index index.php; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
| include fastcgi_params; | |
| } | |
| # disallow access to dot files | |
| location ~ /\. { | |
| deny all; | |
| } | |
| # domain specific settings | |
| include $base/$domain/*.nginx.conf; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment