最近因为一个项目的需要,我选择的环境是Ubuntu+Nginx+Symfony1.4
第一次用nginx+symfony的这种环境,不知道有用的的没有。比Apache相比,效率等方面有没有太大区别。
下面是我的nginx的配置,下面是symfony 1.4的配置
- server {
- listen 8081;
- server_name localhost;
- charset utf-8;
- root /var/sitLims/web/;
- access_log /var/sitLims/log/host.access.log;
- error_log /var/sitLims/log/host.error.log warn;
- location / {
- index index.php;
- try_files $uri /index.php?$args;
- }
- #这一段我加了的话,页面就有问题。没办法找到symfony的页面的css等。
- # location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
- # expires max;
- # log_not_found off;
- # }
- location /sf/ {
- alias /var/sitLims/sf/data/web/sf/;
- }
- 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 fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $document_root$script;
- fastcgi_param PATH_INFO $path_info;
- fastcgi_param SCRIPT_NAME $script;
- }
- }
这里我再把Symfony 2.0的配置发一下,我这边测试可以用的。
- server {
- listen 8080;
- server_name localhost;
- root /usr/share/nginx/www/Symfony/web;
- error_log /var/log/nginx/symfony2.error.log;
- access_log /var/log/nginx/symfony2.access.log;
- # strip app.php/ prefix if it is present
- rewrite ^/app\.php/?(.*)$ /$1 permanent;
- location / {
- index app.php;
- try_files $uri @rewriteapp;
- }
- location @rewriteapp {
- rewrite ^(.*)$ /app.php/$1 last;
- }
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- location ~ ^/(app|app_dev)\.php(/|$) {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_split_path_info ^(.+\.php)(/.*)$;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param HTTPS off;
- }
- }
转载于:https://blog.51cto.com/leexiaobo/933737