配置nginx下别名alias支持PHP fastcgi解析
1)参看如下连篇文章:
Nginx设置alias实现虚拟目录 alias与root的用法区别
http://down.chinaz.com/server/201111/1382_1.htm
Nginx下alias支持PHP的问题
http://i.laoer.com/nginx-alias-php.html
2)我的环境是:web根目录在 /var/www/html/中,但是我要加上一个类似于apache的别名目录 /bbs ,此目录不在 web根目录中。
我的配置文件如下:
server {
listen 80;
server_name localhost;
default_type text/plain;
location / {
root /var/www/html;
index index.php index.htm index.html;
}
location = /extension/sub {
set $push_channel_id $arg_exten;
push_subscriber long-poll;
push_subscriber_concurrency broadcast;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location = /extension/pub {
set $push_channel_id $arg_exten;
push_publisher;
push_min_message_buffer_length 0;
push_max_message_buffer_length 0;
push_message_timeout 1h;
push_channel_group broadcast;
default_type text/plain;
#default_type text/html;
}
location /bbs {
alias /opt/bbs/;
index index.html index.htm index.php;
}
location ~ ^/bbs/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
#include fastcgi.conf;
}
}
说明: 上面这个就是成功的例子。但是又如下几点需要注意:
1)location ~ \.php$ {} 段,必须放在 location ~ ^/bbs/.+\.php$ {} 段后面,否则/bbs/的url打不开
2) location ~ ^/bbs/.+\.php$ {} 里面也可以写成如下:
location ~ ^/bbs/.+\.php$ {
root /opt;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
也就是用 变量名 $document_root 代替 /opt; 其实每个 location {}中的 $document_root 都是局部变量,都是在本段配置 root指令指定的路径。
以上配置完全可以通过nginx的第3放插件 echo 模块来得到验证,方法如下:
location /echo {
root /etc/asterisk;
#echo "$document_root";
echo "$fastcgi_script_name";
}
配置nginx下别名alias支持PHP fastcgi解析的更多相关文章
- Nginx目录别名(Alias)支持PHP的配置
需求:通过 example.com 访问 /var/data/www,但通过 example.com/pa 访问的却是 /var/data/phpmyadmin,即保护phpmyadmin不暴露在ww ...
- Ubuntu配置Nginx虚拟主机和支持ThinkPHP
[Nginx配置虚拟主机] 每一个 server { listen 80; server_name www.a.com; ..... } 就表示一台虚拟域名, 然后对应的 ...
- CentOS 下用的是lnmp 的包配置Nginx 下的CI伪静态(搞爽了)
server { listen ; server_name cy.com; index index.html index.htm index.php default.html default.htm ...
- linux下别名alias的设置
我有一个常用目录/volumes/mac/www’,每次都要输入这么长的路径,麻烦,所以有了以下配置 1.vi ~/.bash_profile 2.按住shift + i进入编辑状态 3.插入 ali ...
- 配置nginx虚拟目录配置文件支持tp的pathinfo
lnmp自带的包不好用, 经测试,在相应的conf文件加入这句话即可: location / { if (!-e $request_filename) { rewrite ^(.*)$ /index. ...
- Linux上配置Nginx+PHP5(FastCGI)
原为地址:http://www.laruence.com/2009/07/28/1030.html Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,以事件驱动的方式编写,所以有非常好的性能,同时 ...
- 【解决】nginx 下$_SERVER['PATH_INFO'] 无法获取到内容
Apache是模块加载文件的,默认支持$_SERVER['PATH_INFO'] : 而对于Nginx下, 是不支持PATH INFO的, 也就是它不会默认设置PATH_INFO. 而因为Nginx默 ...
- mac设置终端命令行别名alias(git、npm)
别名(alias)通常被用作对一串或单个命令的简称.懒人必备!当常用到命令行操作的时候,每次输入一长串命令,不厌其烦,自然想到了用简称代替.这里主要介绍两种mac设置别名alias的方式. mac 设 ...
- Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持
前面有关于lnmp环境的搭建,在此就不在赘述.下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持 主要有两个步骤: 一.更改php.ini将;cgi.fi ...
随机推荐
- Textarea高度随内容自适应地增长,无滚动条
<HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; char ...
- easyUI之layout
此组件与easyUI中的其它组件加载的方式相同,载为class方式和js方式,但此组件更多的是用class方式,其它的用js方式更为灵活.它继承panel组件及resize组件. 包括多个<di ...
- sql compact 使用EF无法更新的问题?
1.问题一是表中没有主键会报一些莫名其妙的错误. 2.数据库文件被默认复制到了Debug/Release目录,实际调试或运行时发现原有数据库没有被更新.
- 创建对象的最好方式&最好的继承机制(代码实例)
/* 创建对象的最好方式:混合的构造函数/原型方式, *用构造函数定义对象的所有非函数属性,用原型方式定义对象的函数属性(方法) */ function People(sname){ this.nam ...
- sql常用语句--转载
一.基础 .说明:创建数据库 CREATE DATABASE database-name .说明:删除数据库 drop database dbname .说明:备份sql server --- 创建 ...
- [mybatis] mybatis错误:Invalid bound statement (not found)
点击菜单抛出异常: org.springframework.web.util.NestedServletException: Request processing failed; nested exc ...
- Jar mismatch! Fix your dependencies的问题
在开发Android项目的时候,有时需要引用多个项目作为library.在引用项目的时候,有时会出现“Jar mismatch! Fix your dependencies”错误. 这是因为两个项目的 ...
- Java ArrayList操作
import java.util.ArrayList; import java.util.List; import java.util.Iterator; public class Study { p ...
- OpenSSL库验证PKCS7签名
使用Crypto库签名和验证签名请参考Crypto库实现PKCS7签名与签名验证,可以使用OpenSSL库验证Crypto签名,OpenSSL验证签名可使用简单的代码描述如下: //signature ...
- phpstorm 配置自带webserver ,配置根目录
版权声明:本文为博主原创文章,未经博主允许不得转载. from http://blog.csdn.net/pony_maggie/article/details/52367093 目录(?)[-] ...