Zend Framework configuration of Nginx rewrite

 

https://www.cnblogs.com/shuaixf/archive/2012/10/12/2722009.html

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;
             #  }
      # } 
}

  

Turn: 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.

Turn: 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 does not support Apache's .htaccess file, you need to write Nginx rewrite rules in the configuration file. Most of Apache RewriteRule command can not put your modified directly using Nginx. You just put into RewriteRule rewrite, [L] changed last like it, you can look at specific Nginx Rewrite the document.

http://wiki.nginx.org/NginxHttpRewriteModule

 

 


 

{Server 
    the listen 80; 
    server_name wenda.localhost.com; 
    index the index.php; 
    the root / the mysite / Wenda; 

    # set time expires, and the max-age 
    ..? location ~ * "^ + \ (jpe g | gif | css | ? PNG | JS | ico | pdf | ZIP | tar | t GZ | MP3 | WAV | SWF) $ "{ 
        the Expires 30d; 
        log_not_found OFF; 
    } 
             
    # settings are not anti-ask directory 
    location ~ ^ / (application | library | var ) / { 
        the deny All; 
    } 
    
    # request directed to the index.php 
    LOCATION / { 
        index the 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;
    }
}

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

 

Guess you like

Origin www.cnblogs.com/yipianchuyun/p/11076339.html