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