[tags]nginx, server, symfony[/tags]
I almost gave up on nginx and was going to settle on lighttpd or Apache, but I decided to check the symfony list and in minutes Kiril Angov (Kupokomapa) answered with a working nginx configuration. This is why I like the symfony community
Here's what works (Note: This requires a running FastCGI server):
server {
listen 80;
server_name mysite.com *;
root /var/www/mysite.com/web;
index index.php;
charset utf-8;
location / {
# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
expires max;
break;
}
if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
rewrite ^(.*) /index.php last;
}
}
location ~ \.php($|/) {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/mysite.com/web$script;
fastcgi_param PATH_INFO $path_info;
}
}
This works in my Ubuntu instance of nginx. Other customziations to this might need to occur, but it's fairly solid so far.



Hey,
I was not aware of the nginx project. Why did you choose it above apache or lighttpd?
Cheers, Thierry
i am curious why you would choose this above apache or lighthttpd also.
Hi Thierry/digitalbase,
So this configuration is on the new server for reviewsby.us. The old server was an Apache2 server. I had been getting frustrated with Apache2 and to some extent my VPS, so my coworkers recommended slicehost and the slicehosters seem to like nginx and lighttpd.
Nginx however doesn’t suffer from the memory leaks that plague lighttpd. It also has a very good rewrite system (better than lighty AFAIK) and it’s easy to configure. I’ve also heard that you can just throw stuff at nginx and it will keep serving… I like that
It’s not in production yet, I’m switching the DNS as we speak, so it should be online this week.
Best,
-d
So what provides the fastcgi process on port 9000 ?
Hi,
I’ve installed NginX/FastCGI/Symfony. It works fast
but I have a small problem with rewriting.
Accessing e.g.
http://localhost:90/frontend_dev.phpis OK. Loads everything OK (e.g. path to CSS is:href="/sf/sf_web_debug/css/main.css"and a path to an image is/images/flag_greatbritain.png).However, accessing e.g.
http://localhost:90/frontend_dev.php/home/indexshows correct page content, but screws up the links (e.g. same path to CSS becomes:href="/frontend_dev.php/home/index/sf/sf_web_debug/css/main.css"and the image path becomes:/frontend_dev.php/home/index/images/flag_greatbritain.png).At the same time, e.g.
http://localhost:90/home/indexworks fine – shows the page with correct paths.I’ve tried tweaking the rewrite rules for NginX, but couldn’t make it work
Here’s my
nginx.conffile:Any help appreciated
Regards, Sasa
I have exactly the same config as you. The only problem is frontenddev.php only shows when u enter /frontenddev.php After you click on a link, it goes to a symfony 404 page. The url is thinking that frontenddev.php is /modulename/ rather than the controller. Im using symfony 1.4 and the latest version of nginx on ubuntu/debian – Any other help?
Thanks