Green Acorn


Symfony2 Nginx Vhost Configuration

Recently I have been experimenting with Nginx and CouchDB. After managing to get them installed on my Ubuntu virtual machine, I wanted to checkout one of my Symfony2 projects and put Nginx to the test.

Below is an example of my Symfony2 Vhost configuration file which is stored in:

Within the configuration I have also set up a reverse proxy to work with CouchDB to get around the “same origin policy” when working with the jQuery couch plugin.

server {
    # Listen on port 80
    listen 80;

    # Server name being used (exact name, wildcards or regular expression)

    # Document root, make sure this points to your Symfony2 /web directory
    root /home/greenacorn/html/example/html/web;

    # Logging
    error_log /var/log/nginx/;
    access_log /var/log/nginx/;

    # Handle static files, redirect to app.php if not found
    location / {
        try_files $uri /app.php?$query_string;

    # Pass the PHP scripts to FastCGI server
    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS off;

    # reverse proxy for CouchDB (base64 user:pass)
    location /couchdb {
       proxy_set_header Authorization "Basic dXNlcjoxMjM=";

There are quite a few Symfony2 Nginx Vhost examples on the internet, many of them never worked with my Ubuntu set up – resulting in odd redirect loops etc. The above configuration worked and I hope it helps.

Posted in: CouchDB, Nginx, Symfony

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>