博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Zend Framework配置Nginx的rewrite
阅读量:5134 次
发布时间:2019-06-13

本文共 5875 字,大约阅读时间需要 19 分钟。

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

 

转:

 

 

 


 

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 on.

转:

 


 

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 文档。

 

 


 

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

转:

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

你可能感兴趣的文章
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
导入导出数据库和导入导出数据库表
查看>>
linux下操作mysql
查看>>
【03月04日】A股滚动市盈率PE历史新低排名
查看>>
Xcode5和ObjC新特性
查看>>
jvm slot复用
查看>>
高并发系统数据库设计
查看>>
LibSVM for Python 使用
查看>>
入坑的开始~O(∩_∩)O~
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
Windows 7 上安装Visual Studio 2015 失败解决方案
查看>>
iOS按钮长按
查看>>
Shell流程控制
查看>>
CSS属性值currentColor
查看>>
[Leetcode|SQL] Combine Two Tables
查看>>
《DSP using MATLAB》Problem 7.37
查看>>
ROS lesson 1
查看>>
js笔记
查看>>
c风格字符串函数
查看>>