Nginx for Symfony

I would like to seek assistance with configuring nginx for a symfony
project.

So far the examples I have managed to get from Google points to setups
where the symfony project is on the root of the virtual host.

I am trying to setup as a subfolder e.g.
www.example.com/my-symfony-project

I have managed to get it to work partially but it seems whenever it
tries to load the css it will try to load it from a wrong folder;

e.g. project folder = /var/www/myproject/web
then it tries to load main.css through
/var/www/myproject/web/var/www/myproject/web/main.css which is not
correct.

Also how do I tell nginx to always load all references to the sf folder
(e.g. /var/www/myproject/web/sf) to the symfony data folder?

Thank you

Hi,

On Sam 24.05.2008 20:51, John Huong wrote:

I would like to seek assistance with configuring nginx for a symfony
project.

[snipp]

Also how do I tell nginx to always load all references to the sf
folder (e.g. /var/www/myproject/web/sf) to the symfony data folder?

I have this working setup:

server {
.
.
.
location / {
root /home/httpd/virtserver//html;

       if ($request_filename !~ 

“.(js|htc|ico|gif|jpg|png|css|htm)$”) {
rewrite ^(.*) /index.php last;
}
index index.html index.htm;
}

     location /sf/ {
       root /home/php/lib/php/data/symfony/web;
     }

     location ~ \.php($|/) {

       set  $script     $uri;
       set  $path_info  "";

       if ($uri ~ "^(.+\.php)(/.+)") {
         set  $script     $1;
         set  $path_info  $2;
       }

       include        fastcgi_params;

       fastcgi_index  index.php;

       fastcgi_param  SCRIPT_FILENAME 

/home/php/projects/symfony/web$script;
fastcgi_param PATH_INFO $path_info;

       fastcgi_pass   127.0.0.1:8085;
     }
  }

Hth

Aleks

Hello Aleksandar,

Saturday, May 24, 2008, 9:18:20 PM, you wrote:

Hi,

On Sam 24.05.2008 20:51, John Huong wrote:

I would like to seek assistance with configuring nginx for a symfony
project.

[snipp]

Also how do I tell nginx to always load all references to the sf
folder (e.g. /var/www/myproject/web/sf) to the symfony data folder?

I have this working setup:

server {
.
.
.
location / {

  •        root   /home/httpd/virtserver/<DOMAIN>/html;
    
  •        if ($request_filename !~ 
    

“.(js|htc|ico|gif|jpg|png|css|htm)$”) {

         rewrite ^(.*) /index.php last;
  •        }
    
  •        index  index.html index.htm;
    
     }
  •      location ~ \.(js|htc|ico|gif|jpg|png|css|html?)$ {
    
  •        root   /home/httpd/virtserver/<DOMAIN>/html;
    
  •        index  index.html index.htm;
         }
    
     location /sf/ {
       root /home/php/lib/php/data/symfony/web;
     }
     location ~ \.php($|/) {
       set  $script     $uri;
       set  $path_info  "";
       if ($uri ~ "^(.+\.php)(/.+)") {
         set  $script     $1;
         set  $path_info  $2;
       }
       include        fastcgi_params;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME 

/home/php/projects/symfony/web$script;
fastcgi_param PATH_INFO $path_info;

       fastcgi_pass   127.0.0.1:8085;
     }
  }

Hth

Hi Denis,

On Sam 24.05.2008 21:43, Denis F. Latypoff wrote:

Saturday, May 24, 2008, 9:18:20 PM, you wrote:

  •        root   /home/httpd/virtserver/<DOMAIN>/html;
    
  •        index  index.html index.htm;
    

Thank you.

Cheers

Aleks

Hi John,

On Sam 24.05.2008 23:54, John Huong wrote:

Hi Aleks,

Thanks for the tip, However, what if I need to have my symfony project
hosted at location /myproject/ ?

Ok?!

maybe

location /myproject/ {
.
.
}

In my symfony project’s web folder there is a .htaccess file.

For apache I would have a line in that file that is
RewriteBase /myproject

What is equivalent in nginx?

On Son 25.05.2008 00:24, John Huong wrote:

In my symfony project’s web folder there is a .htaccess file.

For apache I would have a line in that file that is
RewriteBase /myproject

What is equivalent in nginx?

you can do like this:

server {
root $FULL_SYMFONY_PROJECT_WEBFOLDER_PATH;
location php
location ~ …
}

please take this parts from the mails before :wink:

Cheers

Aleks

Hi Aleks,

Thanks for the tip, However, what if I need to have my symfony project
hosted at location /myproject/ ?

I’ve tried to copy the similar setting.

I can see the symfony initial project page by accessing
http://myhostname/myproject/index.php

However it seems http://myhostname/myproject/mymodule/index.php does not
work

Further more it does not seem to load the css and image files under the
myproject/images or myproject/css.

Ok here is one part:

2008/05/25 00:46:08 [error] 4421#0: *5 open()
“/usr/share/php/data/symfony/web/sf/myproject/sf/sf_default/images/icons/ok48.png”
failed (2: No such file or directory), client: 192.168.11.86, server:
localhost, request: “GET /myproject/sf/sf_default/images/icons/ok48.png
HTTP/1.1”, host: “10.1.1.88:9891”, referrer:
http://10.1.1.88:9891/myproject/index.php

On Son 25.05.2008 08:43, John Huong wrote:

Ok here is one part:

2008/05/25 00:46:08 [error] 4421#0: *5 open()
“/usr/share/php/data/symfony/web/sf/myproject/sf/sf_default/images/icons/ok48.png”
failed (2: No such file or directory), client: 192.168.11.86, server:
localhost, request: “GET /myproject/sf/sf_default/images/icons/ok48.png
HTTP/1.1”, host: “10.1.1.88:9891”, referrer:
http://10.1.1.88:9891/myproject/index.php

and now the conf.

On Son 25.05.2008 00:47, John Huong wrote:

I’ve tried to copy the similar setting.

I can see the symfony initial project page by accessing
http://myhostname/myproject/index.php

However it seems http://myhostname/myproject/mymodule/index.php does
not work

Further more it does not seem to load the css and image files under
the myproject/images or myproject/css.

please can you provide us with some error logs?

myproject is a folder under /var/www/nginx-default

server {
listen 9891;
server_name localhost myserver;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /var/www/nginx-default;
        index  index.html index.htm index.php;
    }

    location /myproject/
    {
       rewrite ^(.*) index.php last;
    }

    location /myproject/sf/ {
    root /usr/share/php/data/symfony/web/sf/;
    }
    #
    location ~ \.php($|/) {
    #    root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME

/var/www/nginx-default$fastcgi_script_name;
include fastcgi_params;
}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Hi Kupo,

Yes you are right in regards to Symfony routing. I have placed the .php
as a habit :).

I already have the project running successfully under Apache, but I
would like to use it with nginx simply because I would like to see if it
would a difference especially with everyone that I know off touting how
much more stable Apache is.

Please help.

John, I suggest you run sumfony under apache to begin with as it seems
you are trying two big things at the same time and you will just go in
circles.

http://myhostname/myproject/mymodule/index.php

The above is not how the routing in Symfony works. Try
http://myhostname/myproject/mymodule or
http://myhostname/myproject/mymodule/index

Kupo

On Son 25.05.2008 22:13, John Huong wrote:

John wrote:

2008/05/25 00:46:08 [error] 4421#0: *5 open()
“/usr/share/php/data/symfony/web/sf/myproject/sf/sf_default/images/icons/ok48.png”
failed (2: No such file or directory), client: 192.168.11.86, server:
localhost, request: “GET /myproject/sf/sf_default/images/icons/ok48.png
HTTP/1.1”, host: “10.1.1.88:9891”, referrer:
http://10.1.1.88:9891/myproject/index.php

myproject is a folder under /var/www/nginx-default

[snipp]

a guess:

  •    location /myproject/sf_default {
    
  •   location /myproject/sf_default {
    
  •      root /usr/share/php/data/symfony/web/sf/;
    
  •      root /usr/share/php/data/symfony/web;
    

please take a look which is the correct path for the default symfony
installation.

Aleks