注释主配置文件中的网站根目录
cat /etc/http/conf/httpd.conf
#DocumentRoot "/var/www/html"
##虚拟主机配置
<VirtualHost *:80>
DocumentRoot /web1
ServerName web1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /web2
ServerName web2.com
</VirtualHost>
因为nginx主配置文件引入了conf.d目录,我们推荐每个虚拟主机在该目录下创建一个文件。
[root@localhost ~]# vi /etc/nginx/conf.d/web2.conf
server {
listen 80;
server_name web2.com;
location / {
root /web2;
index index.php index.html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web2/$fastcgi_script_name;
include fastcgi_params;
}
}
创建web目录与测试文件
[root@localhost ~]# mkdir /web2/
[root@localhost ~]# cat /web2/index.html
this web2.
测试
##本地解析添加hosts文件测试
[root@localhost ~]# cat /etc/hosts
192.168.1.104 web2.com
##重启访问测试 如测试apache则重启apache
[root@localhost ~]# service nginx restart
[root@localhost ~]# curl web2.com
this web2.