Skip to content

Instantly share code, notes, and snippets.

@il-katta
Created March 28, 2015 11:18
Show Gist options
  • Save il-katta/3df84eb4b5fa68800b7c to your computer and use it in GitHub Desktop.
Save il-katta/3df84eb4b5fa68800b7c to your computer and use it in GitHub Desktop.
nginx configuration for php apps
# this configuration is absolutely not safe!!
server {
listen 80;
server_name *.localdomain;
access_log /var/log/nginx/users.access.log;
error_log /var/log/nginx/users.error.log info;
#autoindex on;
set $root /home/user/public_html;
set $docRoot $root;
set $dir "";
if ($host ~ "(.*)\.web.runme.sh"){
set $dir $1;
}
if (-d $root/$dir) {
set $docRoot "${root}/${dir}";
}
if (-d $root/$dir/web) {
set $docRoot "${root}/${dir}/web";
}
root $docRoot;
location / {
add_header docRoot $docRoot;
add_header document_root $document_root;
add_header host $host;
add_header dir $dir;
autoindex on;
index index.html index.php web/index.php;
try_files $uri $uri/ /index.php;
}
location ~ [^/]\.php(/|$) {
include fastcgi_params;
set $script $uri;
set $path_info $uri;
if ($args ~* "^(/.+)$") {
set $path_info $1;
}
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
add_header document_root $document_root;
add_header fastcgi_script_name $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment