Skip to content

Instantly share code, notes, and snippets.

@wastemobile
Last active August 29, 2015 14:03
Show Gist options
  • Save wastemobile/f7ed1421105a04aac208 to your computer and use it in GitHub Desktop.
Save wastemobile/f7ed1421105a04aac208 to your computer and use it in GitHub Desktop.
Nginx conf.d
server {
listen 80;
server_name asami.local;
root /Users/wastemobile/site/asami;
index index.php index.html index.htm;
charset UTF-8;
location ~ /\.ht {
deny all;
}
location ~ /(_app|_config|_content|\.git) {
deny all;
}
location ~ /.(yml|yaml|html) {
deny all;
}
location / {
rewrite ^/admin.php(/.*)?$ /admin.php;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name localhost;
root /Users/wastemobile/site/www;
charset UTF-8;
location ~ /\.ht {
deny all;
}
location ~ /(_app|_config|_content|\.git) {
deny all;
}
location ~ /.(yml|yaml|html) {
deny all;
}
location / {
rewrite ^/admin.php(/.*)?$ /admin.php;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /phpmyadmin {
alias /usr/local/share/phpmyadmin;
index index.php index.html index.htm;
}
}
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 break;
break;
}
rewrite themes/.*/(layouts|pages|partials)/.*.htm /index.php break;
rewrite uploads/protected/.* /index.php break;
server {
set $domain 'yourdomain.com';
server_name $domain;
root /home/$domain/public;
access_log /home/$domain/logs/access.log;
error_log /home/$domain/logs/error.log;
# Cache static files for as long as possible
location ~* \.(?:xml|ogg|mp3|mp4|ogv|svg|svgz|eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico)$ {
try_files $uri =404;
expires max;
access_log off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# Deny access to configuration files
location ~* ^/_config {
deny all;
return 404;
}
location ~ /(_app|_config|_content|/layouts/) {
deny all;
return 404;
}
location ~ /.(yml|yaml|html) { deny all; }
# Return a static file, if it exists, or pass to front controller
location / {
rewrite ^/admin.php.*$ /admin.php;
try_files $uri $uri/ /index.php?$args;
}
# Pass PHP requests on to PHP-FPM
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php5-fpm.sock;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
try_files $uri $uri/ /index.php?$args;
include fastcgi_params;
}
}
# rewrite from example.com to www.example.com
server {
listen 80;
server_name example.com;
rewrite ^(.+?)/?$ http://www.example.com$1 permanent;
}
server {
listen 80;
server_name www.example.com;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;
root /var/www/example.com/public_html;
location / {
index index.php;
# serve static files directly
if (-f $request_filename) {
access_log off;
expires 30d;
break;
}
### BACKEND
if ($request_filename ~ /symphony/) {
rewrite ^/symphony/?$ /index.php?mode=administration&$query_string last;
rewrite ^/symphony(/(.*/?))?$ /index.php?symphony-page=$1&mode=administration&$query_string last;
}
### IMAGE RULES
rewrite ^/image/(.+.(jpg|gif|jpeg|png|bmp|JPG|GIF|JPEG|PNG|BMP))$ /extensions/jit_image_manipulation/lib/image.php?param=$1 last;
## Add trailing slash
rewrite ^(.*[^/])$ $1/ permanent;
### MAIN REWRITE - This will ignore directories
if (!-d $request_filename) {
rewrite ^/(.*)$ /index.php?symphony-page=$1 last;
}
}
location ~ .php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/public_html$fastcgi_script_name;
}
}
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name 192.34.59.214;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment