Hosting symfony based website with nginx
December 4th, 2009
The following config file allows you to host symfony based website with Nginx web server.
server {
listen 80;
server_name www.your-url.com;
#Enable Gzip
gzip on;
gzip_min_length 1000;
gzip_types text/plain application/xml;
gzip_disable "MSIE [1-6]\.";
#where to put log files
access_log /var/log/nginx/your-url.com.access.log;
#project's main directory
root /full/path/web/;
#change the following to index.php on production server.
index front_dev.php;
charset utf-8;
location /sf {
#path to folder where all symfony assets are located
alias /full/path/lib/symfony/data/web/sf;
}
location / {
# If the file exists as a static file serve it directly without
# running al l the other rewite tests on it
if (-f $request_filename) {
expires 1m;
break;
}
if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
#change front_dev to index.php on production server
rewrite ^(.*) /front_dev.php$1 last;
}
}
location ~ "^(.+\.php)($|/)" {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)($|/)") {
set $script $1;
}
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /full/path/web$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
}
}