[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