最近因为一个项目的需要,我选择的环境是Ubuntu+Nginx+Symfony1.4

第一次用nginx+symfony的这种环境,不知道有用的的没有。比Apache相比,效率等方面有没有太大区别。

下面是我的nginx的配置,下面是symfony 1.4的配置

 
  
  1. server { 
  2.     listen       8081; 
  3.     server_name  localhost; 
  4.  
  5.     charset      utf-8; 
  6.  
  7.     root         /var/sitLims/web/; 
  8.     access_log   /var/sitLims/log/host.access.log; 
  9.     error_log    /var/sitLims/log/host.error.log  warn; 
  10.  
  11.     location / { 
  12.         index        index.php; 
  13.         try_files    $uri /index.php?$args; 
  14.     } 
  15.   #这一段我加了的话,页面就有问题。没办法找到symfony的页面的css等。
  16.    # location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
  17.    # expires max; 
  18.    #     log_not_found off; 
  19.    # } 
  20.  
  21.     location /sf/ { 
  22.         alias /var/sitLims/sf/data/web/sf/; 
  23.     } 
  24.  
  25.     location ~ \.php($|/) { 
  26.         set $script    $uri; 
  27.         set $path_info ""; 
  28.  
  29.         if ($uri ~ "^(.+\.php)(/.*)"){ 
  30.             set $script       $1; 
  31.             set $path_info    $2; 
  32.         } 
  33.  
  34.         fastcgi_pass   127.0.0.1:9000; 
  35.         include        fastcgi_params; 
  36.         fastcgi_param  SCRIPT_FILENAME    $document_root$script; 
  37.         fastcgi_param  PATH_INFO          $path_info; 
  38.         fastcgi_param  SCRIPT_NAME        $script; 
  39.     } 

 这里我再把Symfony 2.0的配置发一下,我这边测试可以用的。

 

 
  
  1. server { 
  2.   listen 8080; 
  3.  
  4.   server_name localhost; 
  5.   root /usr/share/nginx/www/Symfony/web; 
  6.  
  7.   error_log /var/log/nginx/symfony2.error.log; 
  8.   access_log /var/log/nginx/symfony2.access.log; 
  9.  
  10.   # strip app.php/ prefix if it is present 
  11.   rewrite ^/app\.php/?(.*)$ /$1 permanent; 
  12.  
  13.   location / { 
  14.     index app.php; 
  15.     try_files $uri @rewriteapp; 
  16.   } 
  17.  
  18.   location @rewriteapp { 
  19.     rewrite ^(.*)$ /app.php/$1 last; 
  20.   } 
  21.  
  22.   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  23.   location ~ ^/(app|app_dev)\.php(/|$) { 
  24.     fastcgi_pass   127.0.0.1:9000; 
  25.     fastcgi_split_path_info ^(.+\.php)(/.*)$; 
  26.     include fastcgi_params; 
  27.     fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 
  28.     fastcgi_param  HTTPS              off; 
  29.   }