Skip to content

Instantly share code, notes, and snippets.

@abovedave
Last active December 25, 2015 20:19
Show Gist options
  • Save abovedave/7034147 to your computer and use it in GitHub Desktop.
Save abovedave/7034147 to your computer and use it in GitHub Desktop.
nginx server configuration for Symphony CMS
server {
server_name www.example.com;
rewrite ^ $scheme://example.com$uri permanent;
}
server {
listen 80;
server_name example.com;
root /srv/www/example.com/public_html/;
location / {
index index.php;
## Add trailing slash
rewrite ^(.*[^/])$ $1/ permanent;
### MAIN REWRITE - This will ignore directories
if (!-d $request_filename) {
rewrite ^/(.*)$ /index.php?symphony-page=$1 last;
}
}
# Symphony admin redirects
location ~ ^/symphony(/?.*)$ {
# If not requesting assest files...
if (!-f $request_filename) {
# ...internal redirect Symphony admin, which in turn will redirect to...
rewrite ^/symphony/?$ /index.php?mode=administration&$query_string last;
# ...some admin page.
rewrite ^/symphony(/(.*/?))?$ /index.php?symphony-page=$1&mode=administration&$query_string last;
}
}
# Any request to /images/ that is not a real file, send it to JIT
location ~ ^/image/(.*)$ {
try_files $uri $uri/ /extensions/jit_image_manipulation/lib/image.php?param=$1;
}
# Route PHP requests
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public_html$fastcgi_script_name;
}
# Expiry headers for static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1y;
log_not_found off;
access_log off;
add_header Vary Accept-Encoding;
}
# Hide GIT related files
location ~ /\.git {
deny all;
}
}
@jimlambie
Copy link

Hey man, I had to edit the PHP block slightly to run on Digital Ocean using Ubuntu 12.04, PHP 5.3.10. From this post http://stackoverflow.com/questions/17777774/my-nginx-fastcgi-configuration-downloads-php-files-instead-of-executing-them

# Route PHP requests
location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment