nginx虚拟目录支持PHP,nginx设置虚拟目录

本文介绍了如何在CentOS 6.3的Nginx环境中设置两个虚拟目录blog.aaa.com和bbs.bbb.com,配置了相应的PHP支持,并详细步骤包括添加配置文件、server块定义和PHP处理。

nginx建立虚拟目录的配置文件放在/etc/nginx/conf.d目录下。系统用的是CentOS6.3。

首先在nginx.conf中查找有没有:

include /etc/nginx/conf.d/*.conf

这一句,没有的话要加在http块内。

添加虚拟目录

比如要放两个虚拟目录:

blog.aaa.com在/home/blog.aaa目录

bbs.bbb.com在/home/bbs.bbb目录

我们把这两个虚拟目录写在一个配置文件里。

cd /etc/nginx/conf.d

vim virtualhost.conf

添加:

server {

listen 80;

server_name blog.aaa.com;

access_log /var/log/nginx/blog.aaa.log main;

location / {

root /home/blog.aaa;

index index.php index.html index.htm;

}

location ~ \.php$ {

root /home/blog.aaa;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /home/blog.aaa$fastcgi_script_name;

include fastcgi_params;

}

}

server {

listen 80;

server_name bbs.bbb.com;

access_log /var/log/nginx/bbs.bbb.log main;

location / {

root /home/bbs.bbb;

index index.php index.html index.htm;

}

location ~ \.php$ {

root /home/bbs.bbb;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /home/bbs.bbb$fastcgi_script_name;

include fastcgi_params;

}

}

一个server块对应一个虚拟目录。location ~ \.php$块的作用是让虚拟目录支持php。

更新nginx配置:

service nginx reload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值