Skip to content

Instantly share code, notes, and snippets.

@marydn
Created February 26, 2018 08:51
Show Gist options
  • Save marydn/9709a29d394074bf73c553c4668ed10f to your computer and use it in GitHub Desktop.
Save marydn/9709a29d394074bf73c553c4668ed10f to your computer and use it in GitHub Desktop.
Nginx virtualhost for Symfony2
server {
server_name project.local;
root /var/www/project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_read_timeout 180;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
error_log /var/www/project/app/logs/nginx_error.log;
access_log /var/www/project/app/logs/nginx_access.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment