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解析的更多相关文章

  1. Nginx目录别名(Alias)支持PHP的配置

    需求:通过 example.com 访问 /var/data/www,但通过 example.com/pa 访问的却是 /var/data/phpmyadmin,即保护phpmyadmin不暴露在ww ...

  2. Ubuntu配置Nginx虚拟主机和支持ThinkPHP

    [Nginx配置虚拟主机] 每一个 server { listen       80;         server_name  www.a.com; ..... } 就表示一台虚拟域名, 然后对应的 ...

  3. CentOS 下用的是lnmp 的包配置Nginx 下的CI伪静态(搞爽了)

    server { listen ; server_name cy.com; index index.html index.htm index.php default.html default.htm ...

  4. linux下别名alias的设置

    我有一个常用目录/volumes/mac/www’,每次都要输入这么长的路径,麻烦,所以有了以下配置 1.vi ~/.bash_profile 2.按住shift + i进入编辑状态 3.插入 ali ...

  5. 配置nginx虚拟目录配置文件支持tp的pathinfo

    lnmp自带的包不好用, 经测试,在相应的conf文件加入这句话即可: location / { if (!-e $request_filename) { rewrite ^(.*)$ /index. ...

  6. Linux上配置Nginx+PHP5(FastCGI)

    原为地址:http://www.laruence.com/2009/07/28/1030.html Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,以事件驱动的方式编写,所以有非常好的性能,同时 ...

  7. 【解决】nginx 下$_SERVER['PATH_INFO'] 无法获取到内容

    Apache是模块加载文件的,默认支持$_SERVER['PATH_INFO'] : 而对于Nginx下, 是不支持PATH INFO的, 也就是它不会默认设置PATH_INFO. 而因为Nginx默 ...

  8. mac设置终端命令行别名alias(git、npm)

    别名(alias)通常被用作对一串或单个命令的简称.懒人必备!当常用到命令行操作的时候,每次输入一长串命令,不厌其烦,自然想到了用简称代替.这里主要介绍两种mac设置别名alias的方式. mac 设 ...

  9. Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持

    前面有关于lnmp环境的搭建,在此就不在赘述.下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持 主要有两个步骤: 一.更改php.ini将;cgi.fi ...

随机推荐

  1. C# 数组,ArrayList与List对象的区别

    在C#中,当我们想要存储一组对象的时候,就会想到用数组,ArrayList,List这三个对象了.那么这三者到底有什么样的区别呢? 我们先来了解一下数组,因为数组在C#中是最早出现的. 数组 数组有很 ...

  2. Q3: Linked List Cycle II

    问题描述 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...

  3. 【转】.NET 安装和部署(Installer) 如何卸载上一个版本

    前言 当使用.NET“安装项目”打包的安装文件,再次安装的时候会弹出如下提示,这个时候会让我们很郁闷,怎样才能自动卸载上一个安装的版本呢?方法很简单,只需简单的两个操作步骤即可解决. 操作步骤 主要由 ...

  4. html之内联标签img

    img创建的是被链接图像的占位空间,它不会真正地在网页插入图像. 两个必须属性: src:图像的超链接 alt:图像的替代文本 可选属性: height:高度 width:宽度 ismap:将图像定义 ...

  5. centos6.5 安装iptables

    阿里云默认是没有安装iptables 安装 yum install -t iptables yum install iptables-services 检查iptables服务的状态 service ...

  6. Javascript 去掉字符串前后空格的五种方法

    第一种:循环检查替换 [javascript] //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 functi ...

  7. ArrayList和LinkedList遍历方式及性能对比分析

    ArrayList和LinkedList的几种循环遍历方式及性能对比分析 主要介绍ArrayList和LinkedList这两种list的五种循环遍历方式,各种方式的性能测试对比,根据ArrayLis ...

  8. nodejs小问题:express不是内部或外部命令

    来源:http://jingyan.baidu.com/article/922554468a3466851648f419.html 一时兴起想学习点东西,准备在heroku上部署一个Node.js的小 ...

  9. txt用Itunes同步到IPhone上

    纯水的LGF160s换了IPhone 5,想把原来txt的文件拷到手机上.百度只是有老版本的,最新也是11的.现在用12.06版的,菜单已经不太一样.找了半天,分享一下.

  10. ARM地址映射

    转自:http://blog.csdn.net/a3163504123/article/details/10958229 重映射之后,一般原来的地址依然有效.也就是说,可能两个地址,对应一个存储单元. ...