[root conf]# vi /usr/local/nginx/conf/nginx.conf #打开nginx配置文件#
在底部加入:include vhosts/*.conf;
[root ~]# mkdir /usr/local/nginx/conf/vhosts #创建vhosts目录,vhosts在conf目录下#
[root ~]# cd !$ #进入vhosts目录下#
cd /usr/local/nginx/conf/vhosts
[root vhosts]# vim default.conf 创建默认虚拟主机并加入如下配置
server
{
listen 80 default_server; #dafault_server用来标记它是默认虚拟主机的#
server_name 123.com; #域名随便自定义#
index index.html index.htm index.php;
root /tmp/tmp; #目录随便定义#
deny all; #拒绝报有#
}
[root 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