Skip to content

Instantly share code, notes, and snippets.

@androzd
Last active July 14, 2017 10:04
Show Gist options
  • Select an option

  • Save androzd/68cb63765aa68d1200e0 to your computer and use it in GitHub Desktop.

Select an option

Save androzd/68cb63765aa68d1200e0 to your computer and use it in GitHub Desktop.
nginx automatic configuration for laravel, kohana, symfony projects
server {
listen 80;
server_name "~^((?<subdomain>.+)\.)?(?<domain>.+)\.loc$";
set $projects_dir /var/www;
set $project_dir $projects_dir/$domain;
if (-d $projects_dir/$subdomain.$domain) {
set $project_dir $projects_dir/$subdomain.$domain;
}
set $index index.php;
set $root_dir $project_dir/public;
if (-f $project_dir/public/index.php) {
set $root_dir $project_dir/public;
set $index index.php;
}
if (-f $project_dir/wwwroot/index.php) {
set $root_dir $project_dir/wwwroot;
set $index index.php;
}
if (-f $project_dir/web/app_dev.php) {
set $root_dir $project_dir/web;
set $index app_dev.php;
}
if (-f $project_dir/index.php) {
set $root_dir $project_dir;
set $index index.php;
}
index $index;
root $root_dir;
location @rewrites {
rewrite ^/(.*)$ /$index last;
}
location ~ ^/cache {
try_files $uri @rewrites;
expires 30d;
}
location / {
charset utf-8;
try_files $uri $uri/ @rewrites;
}
location ~ \.php$ {
fastcgi_pass unix://var/run/php/php7.0-fpm.sock;
fastcgi_index $index;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment