Nginx下zend framework的设置

由于zf自带的工具,生成的项目都是基于apache的,而nginx和apache的htaccess(即Rewriter规则)又不一样

Java代码   收藏代码
  1. server {  
  2.   listen 80;  
  3.   server_name servername.com;  
  4.   
  5.   root /var/www/zendapp/public;  
  6.   
  7.   location / {  
  8.     index index.php;  
  9.   }  
  10.   
  11.   # Deny access to sensitive files.  
  12.   location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {  
  13.     deny all;  
  14.   }  
  15.   location ~ \.htaccess {  
  16.     deny all;  
  17.   }  
  18.   
  19.   # Rewrite rule adapted from zendapp/public/.htaccess  
  20.   if (!-e $request_filename) {  
  21.     rewrite ^.*$ /index.php last;  
  22.   }  
  23.   #图片/js/css不显示解决  
  24.   location ~* ^.+\.(js|ico|gif|jpg|jpeg|pdf|png|css)$ {  
  25.     access_log   off;  
  26.     expires      7d;  
  27.   }  
  28.   # PHP scripts will be forwarded to fastcgi processess.  
  29.   # Remember that the `fastcgi_pass` directive must specify the same  
  30.   # port on which `spawn-fcgi` runs.  
  31.   location ~ \.php$ {  
  32.     include /etc/nginx/fastcgi_params;  
  33.   
  34.     fastcgi_pass   127.0.0.1:9000;  
  35.     fastcgi_index  index.php;  
  36.   }  
  37.   
  38.   location = /50x.html {  
  39.       root   /var/www/default;  
  40.   }  
  41. }  

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

 

Nginx部署ThinkPHP项目的办法网上通用解决方法的配置如下

Java代码   收藏代码
  1. server {  
  2.  ...  
  3.     location / {  
  4.         index  index.htm index.html index.php;  
  5.         #访问路径的文件不存在则重写URL转交给ThinkPHP处理  
  6.         if (!-e $request_filename) {  
  7.            rewrite  ^/(.*)$  /index.php/$1  last;  
  8.            break;  
  9.         }  
  10.     }  
  11.     location ~ \.php/?.*$ {  
  12.         fastcgi_pass   127.0.0.1:9000;  
  13.         fastcgi_index  index.php;  
  14.         #加载Nginx默认"服务器环境变量"配置  
  15.         include        fastcgi.conf;  
  16.           
  17.         #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量  
  18.         set $fastcgi_script_name2 $fastcgi_script_name;  
  19.         if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
  20.             set $fastcgi_script_name2 $1;  
  21.             set $path_info $2;  
  22.         }  
  23.         fastcgi_param   PATH_INFO $path_info;  
  24.         fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
  25.         fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;  
  26.     }  
  27. }  

nginx多server

1.检查/etc/nginx/nginx.conf配置文件,确保文件中有:include /etc/nginx/conf.d/*.conf;  

Java代码   收藏代码
  1. user  lg;  
  2. worker_processes  2;  
  3. error_log  /var/log/nginx/error.log warn;  
  4. pid        /var/run/nginx.pid;  
  5. events {  
  6.     worker_connections  1024;  
  7.     debug_connection 127.0.0.1;  
  8.     debug_connection 192.168.1.0/24;  
  9. }  
  10. http {  
  11.     include       /etc/nginx/mime.types;  
  12.     #  ......  
  13.     include /etc/nginx/conf.d/*.conf;  
  14. }  

 2.关键步骤,在目录/etc/nginx/conf.d/下面新建文件site1.conf,site2.conf,文件名任意写,自己看明白就OK,后缀名需要与步骤1配置的一致,这里为.conf

 

Nginx多Server反向代理配置

在一个server块中配置多个站点

Java代码   收藏代码
  1. server   
  2. {   
  3.     listen 80;   
  4.     server_name ~^(www\.)?(.+)$;   
  5.     index index.php index.html;   
  6.     root /data/wwwsite/$2;   
  7. }   
 站点的主目录应该类似于这样的结构:
Java代码   收藏代码
  1. /data/wwwsite/ssdr.info   
  2. /data/wwwsite/linuxtone.org   
  3. /data/wwwsite/baidu.com   

 类似

Java代码   收藏代码
  1. server_name http://www.*.yourdomain.com/;  
  2. root /PATH/TO/WEBROOT/$host;  
  3. location / {  
  4.     root   /PATH/TO/WEBROOT/$host/;  
  5.     index  index.php;  
  6. }  
  7. location ~ .php$ {  
  8. fastcgi_param  SCRIPT_FILENAME  /PATH/TO/WEBROOT/$host/$fastcgi_script_name;  
  9. }  

 

在一个server块中为一个站点配置多个二级域名 。

实际网站目录结构中我们通常会为站点的二级域名独立创建一个目录,同样我们可以使用正则的捕获来实现在一个server块中配置多个二级域名:

Java代码   收藏代码
  1. server   
  2. {   
  3.     listen 80;   
  4.     server_name ~^(.+)?\.ssdr\.info$;   
  5.     index index.html;   
  6.     if ($host = ssdr.info){   
  7.     if ($host ~ ^(.*)\.ssdr\.info$ )  
  8.        set $domain $1;   
  9.     }   
  10.     root /data/wwwsite/ssdr.info/$domain/;   
  11. }    

 

站点的目录结构应该如下:

Java代码   收藏代码
  1. /data/wwwsite/ssdr.info/www/   
  2. /data/wwwsite/ssdr.info/nginx/   

这样访问www.ssdr.info时root目录为/data/wwwsite/ssdr.info/www/,nginx.ssdr.info时为/data/wwwsite/ssdr.info/nginx/,以此类推。

后面if语句的作用是将ssdr.info的方位重定向到www.ssdr.info,这样既解决了网站的主目录访问,又可以增加seo中对www.ssdr.info的域名权重
通用配置
Java代码   收藏代码
  1. server  
  2. {  
  3.      listen 80;  
  4.      server_name *.dev.com;  
  5.   
  6.      if ($host ~ ^(.*)\.dev\.com$ )  
  7.      {  
  8.          set $path    /Users/apple/development/$1;  
  9.          set $webpath $path/trunk/htdocs;  
  10.      }  
  11.      root $path/trunk/htdocs;  
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值