Symfony 2 Nginx Config

server {
    root /PATH/TO/PROJECT/web; # make sure you point it at the "web" subfolder
    server_name SERVER_NAME;

    index app.php;
    try_files $uri $uri/ /app.php?$query_string;

    location ~ ^/(app_dev|app)\.php(/|$) {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;

4 thoughts on “Symfony 2 Nginx Config”

  1. @cordoval
    1. create a file (whatever name) in /etc/nginx/sites-avaiable/
    2. chuck the content of this post in, make sure you modify 2 things: server_name sf.mir.local to whatever your virtualhost name is, and root /mnt/projects/sf/web; to where your actual symfony web folder is at
    3. create a symbolic link in /etc/nginx/sites-enabled/, for example, ln -s /etc/nginx/sites-available/symfony /etc/nginx/sites-available/symfony
    4. restart nginx by /etc/init.d/nginx stop and then /etc/init.d/nginx start

    you should be able to find outhow to set up the ubuntu with nginx/php5-fpm by googling it.

  2. Just as an FYI, when I installed php5-fpm the sock file was put into /va/run/ not /var/run/php-fpm

    I’m using Ubuntu 13.10

    For me that meant changing
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_pass unix:/var/run/php-fpm.sock;

Leave a Reply