[root@wjh1 conf]# vi /usr/local/nginx/conf/nginx.conf #打开nginx配置文件#php
在底部加入:include vhosts/*.conf;html
[root@wjh1 ~]# mkdir /usr/local/nginx/conf/vhosts #建立vhosts目录,vhosts在conf目录下#nginx
[root@wjh1 ~]# cd !$ #进入vhosts目录下#vim
cd /usr/local/nginx/conf/vhostscurl
[root@wjh1 vhosts]# vim default.conf 建立默认虚拟主机并加入以下配置测试
serverurl
{.net
listen 80 default_server; #dafault_server用来标记它是默认虚拟主机的#server
server_name 123.com; #域名随便自定义#htm
index index.html index.htm index.php;
root /tmp/tmp; #目录随便定义#
deny all; #拒绝报有#
}
[root@wjh1 vhosts]# mkdir /tmp/tmp #建立刚才自定义的目录#
[root@wjh1 vhosts]# service nginx configtest #检测配置文件有没有错误#
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@wjh1 vhosts]# service nginx reload #从新加载配置文件#
从新载入 Nginx: [肯定]
[root@wjh1 vhosts]# curl -x127.0.0.1:80 www.qq.com -I #测试403#
HTTP/1.1 403 Forbidden
Server: nginx/1.8.0
Date: Thu, 01 Dec 2016 07:58:41 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive