Last active
March 29, 2018 20:10
-
-
Save lav45/5f75aeb8f40f6ac4efa2 to your computer and use it in GitHub Desktop.
Nginx VirtualDocumentRoot
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; | |
server_name ~^((?<sub>[^\.]+)\.)?(?<domain>[^\.]+)\.my$; | |
charset utf-8; | |
client_max_body_size 128m; | |
index index.php index.html index.htm; | |
error_log /var/www/log/nginx.error.log warn; | |
log_not_found on; | |
access_log off; | |
set $web_root /var/www/my/$domain; | |
set $web_path false; | |
set $isYii false; | |
if ( -f $web_root/yii ) { | |
set $isYii $sub; | |
} | |
if ( $isYii ~ ^|www$ ) { | |
set $web_path frontend; | |
} | |
if ( $isYii = 'admin' ) { | |
set $web_path backend; | |
} | |
if ( !-d $web_root/$web_path ) { | |
set $web_path false; | |
} | |
if ( $web_path != false ) { | |
set $web_root $web_root/$web_path; | |
} | |
if ( -d $web_root/$sub ) { | |
set $web_root $web_root/$sub; | |
} | |
if ( -d $web_root/www ) { | |
set $web_root $web_root/www; | |
} | |
if ( -d $web_root/public ) { | |
set $web_root $web_root/public; | |
} | |
if ( -d $web_root/web ) { | |
set $web_root $web_root/web; | |
} | |
root $web_root; | |
location ~ \.php$ { | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SERVER_NAME $http_host; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location = /robots.txt { access_log off; log_not_found off; } | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location ~ /LICENSE { access_log off; log_not_found off; deny all; } | |
location ~ /README { access_log off; log_not_found off; deny all; } | |
location ~ /\. { access_log off; log_not_found off; deny all; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Это универсальный config для nginx.
Данный config позволяет быстро создавать web проекты с произвольным доменом и сразу открыть его в браузере без перезапуска и предварительной настройки nginx.
Данный config кроме Yii подойдет и для такими frameworck-ов как Symfony, Laravel, Zend, ...