Skip to content

Instantly share code, notes, and snippets.

@hyjk2000
Last active January 3, 2019 21:04
Show Gist options
  • Save hyjk2000/b5bb1b9f7186c3c64e83 to your computer and use it in GitHub Desktop.
Save hyjk2000/b5bb1b9f7186c3c64e83 to your computer and use it in GitHub Desktop.
Nginx Virtual Host for PhalconPHP with Gzip and Expires
server {
listen 80;
server_name example.com;
# server_name _; # if no server name
root /usr/share/nginx/www/example.com/public;
index index.php index.html index.htm;
# rewrite to Phalcon bootstrap
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
# gzip compression
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# PHP-FPM
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php5-fpm.sock;
# NOTE: Could be "unix:/var/run/php-fpm/php-fpm.sock" in some distros
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# no logging for favicon
location ~ favicon.ico$ {
access_log off;
}
# deny access to .htaccess files
location ~ /\.ht {
deny all;
}
# expires of assets (per extension)
location ~ .(jpe?g|gif|png|webp|ico|css|js|zip|tgz|gz|rar|bz2|7z|tar|pdf|txt|mp4|m4v|webm|flv|wav|swf)$ {
if ($args ~ [0-9]+) {
expires max;
} else {
expires 30d;
}
}
# expires of assets (per path)
location ~ ^/(css|js|img|files) {
if ($args ~ [0-9]+) {
expires max;
} else {
expires 30d;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment