Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vedmant/524a3bb179cb22fe0c8dbe615f463589 to your computer and use it in GitHub Desktop.
Save vedmant/524a3bb179cb22fe0c8dbe615f463589 to your computer and use it in GitHub Desktop.
# List of upstream php servers
upstream project_php_fpm {
least_conn;
ip_hash;
server 127.0.0.1:9101;
server 127.0.0.1:9102;
}
proxy_cache_path /home/user/project/nginx/cache levels=1:2 keys_zone=project_cache:10m max_size=10g inactive=60m; # use_temp_path=off;
fastcgi_cache_path /home/user/project/nginx/fcgicache levels=1:2 keys_zone=project_fcgicache:100m inactive=60m;
server {
listen *:80;
server_name project.com www.project.com;
root /home/user/project/web;
access_log /home/user/project/logs/access.log;
error_log /home/user/project/logs/error.log;
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
# Turn on maintenance if maintenance.html exists
if (-f $document_root/maintenance.html) {
return 503;
}
index app.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
set $skip_cache 0;
# POST requests should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|info)\.php(/|$)|/status {
fastcgi_cache project_fcgicache;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache_key "$scheme$request_method$host$request_uri$args";
fastcgi_cache_valid 200 60m;
#fastcgi_ignore_headers Cache-Control Expires Set-Cookie Vary;
# Pass request to php-fpm pools
fastcgi_pass project_php_fpm;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param HTTPS off;
# Change application environment here
fastcgi_param APP_ENV dev;
}
# Static files rule-set
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|css|js|html)$ {
# Set rules only if the file actually exists.
if (-f $request_filename) {
access_log off;
expires 30d;
}
proxy_cache project_cache;
proxy_cache_key $host$uri#is_args$args;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 302 301 12h;
proxy_cache_valid any 1m;
# Rewrite to app.php if the requested file does not exist.
try_files $uri @rewriteapp;
}
# Maintenance mode error settings
error_page 503 @maintenance;
location @maintenance {
open_file_cache_valid 0s;
rewrite ^(/maintenance\.png)$ /$1 break;
rewrite ^(.*)$ /maintenance.html break;
}
# Return 404 for any other php file
location ~ \.php(/|$) {
# Write this request to separate log
access_log /home/user/project/logs/access-php.log;
# Keep log in access.log too
access_log /home/user/project/logs/access.log;
return 404;
}
# Deny all .ht* files with 404 response
location ~ /\.ht {
return 404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment