Zend Framework配置Nginx的rewrite

user  www www;

worker_processes 10;

error_log  /data1/logs/nginx_error.log  crit;

#pid        logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process. 
worker_rlimit_nofile 51200;

events 
{
       use epoll;

       worker_connections 51200;
}

http 
{
       include       conf/mime.types;
       default_type  application/octet-stream;

       charset  utf-8;
       
       server_names_hash_bucket_size 128;
       
       #sendfile on;
       #tcp_nopush     on;

       keepalive_timeout 60;

       tcp_nodelay on;

       gzip on;
       gzip_min_length  1k;
       gzip_buffers     4 8k;
       gzip_http_version 1.1; 
       gzip_types       text/plain application/x-javascript text/css text/html application/xml;

       server
       {
               listen       80;
               server_name localhost.sample.com;
               index index.html index.htm index.php;
               root  /var/local/htdocs;

               #if (-d $request_filename)
               #{
               #       rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
               #}
               location /shlevod {
   index index.php;
    #配置开始
          if (!-f $request_filename)
   {
    rewrite ^/(.+)$ /shlevod/index.php?$1 last;
   }
  }
  location ~* ^.+\.(js|ico|gif|jpg|jpeg|pdf|png|css)$ {
            access_log   off;
            expires      7d;
  }

#配置结束
               location ~ .*\.php?$
               {
                    include conf/fcgi.conf;      
                    fastcgi_pass  127.0.0.1:8099;
                    fastcgi_index index.php;
               }

               log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                                     '$status $body_bytes_sent "$http_referer" '
                                     '"$http_user_agent" $http_x_forwarded_for';
               access_log  /data1/logs/access.log  access;
       }

       #server
       #{
        #       listen  80;
         #      server_name  status.blog.s135.com;

          #     location / {
           #         stub_status on;
            #        access_log   off;
             #  }
      # } 
}

 

转:http://www.cnblogs.com/witer666/archive/2010/03/04/1678461.html

 

 

 


 

Nginx is a powerful HTTP server that is quickly gaining widespread usage on the internet, due to its flexibility and performance benefits. I highly recommend using Nginx over Apache for all new web applications. I use Nginx on all my own sites, and am very pleased with it.

To run an MVC (Model – View – Controller) application with the Zend Framework, your HTTP server must be properly configured in order to correctly rewrite requests. This is how it can be accomplished with Nginx.

In the ‘sites-enabled’ directory for Nginx (usually at ‘/etc/nginx/sites-enabled’ on Unix), you’ll need to create a configuration file for your site. Name this file ‘mysite‘ (use your real site name) with no extension. Now open up the file, and let’s tell Nginx what to do.

Contents of ‘mysite‘. Be sure to replace mysite.com (and all paths) with the correct values:

server {
    listen 80;
    server_name mysite.com;
    root /var/www/mysite/public;
    index /index.php;
 
    location / {
        if (!-f $request_filename) {
            rewrite ^(.*)$ /index.php?q=$1 last;
            break;
        }
    }
 
    location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico) {
        expires 30d;
    }
 
    location ~ .(php|phtml)$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/mysite/public$fastcgi_script_name;
 
        include /etc/nginx/fastcgi_params;
    }
}

 

What this does is tells Nginx to listen for requests to ‘mysite.com’, and rewrite then to /index.php, so that Zend can take care of them from there.

Running PHP with Nginx is slightly more involved than running it with Apache. This article assumes you have PHP configured to run with FastCGI, if not, please see this article onrunning PHP with Nginx.

转:http://zendcoding.com/configure-nginx-for-use-with-zend-mvc

 


 

   server {
        listen 80;
        server_name audit.local;
        root /app/audit/public;
        access_log  /app/audit/logs/audit.access.log main;
        error_log   /app/audit/logs/audit.error.log;
        location / {
            index  index.php;
        # If file not found, redirect to Zend handling, we can remove the (if) here and go directly rewrite
            if (!-f $request_filename){
                rewrite ^/(.+)$ /index.php?$1& last;
            }
        }
        location ~* ^.+\.(js|ico|gif|jpg|jpeg|pdf|png|css)$ {
          access_log   off;
          expires      7d;
        }
        location ~ .*\.php?$ {
            fastcgi_pass   127.0.0.1:36;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        error_page  404             http://audit.local/error;
   }

 

Nginx 不支持 Apache 的 .htaccess 文件,所以需要在 Nginx 配置文件中编写重写规则。Apache 的绝大部分 RewriteRule 命令都可以不做修改的放到 Nginx 中直接使用。你只要把 RewriteRule 改成 rewrite,[L] 改成 last 之类的就可以了,具体可以看一下 Nginx 的 Rewrite 文档。

http://wiki.nginx.org/NginxHttpRewriteModule

 

 


 

server {
    listen          80;
    server_name     wenda.localhost.com;
    index           index.php;
    root            /mysite/wenda;

    # 设置expires和max-age的时间
    location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
        expires         30d;
        log_not_found   off;
    } 
             
    #设置不被防问的目录
    location ~ ^/(application|library|var)/ {
        deny all;
    }
    
    #将request指向index.php
    location / {
        index  index.php index.html index.htm;
        if (-f $request_filename) {
            break;
        }
        if (-d $request_filename) {
            break;
        }
        rewrite ^(.+)$ /index.php last;
    }
    
    #引用PHP CGI
    location ~ .*\.(php|php5)?$ {
        fastcgi_pass   127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
        fastcgi_read_timeout 600;
    }
}

转:http://my.oschina.net/rickyfeng/blog/40352

你可能感兴趣的:(framework)