标签:linux
背景:
在www虚拟主机站点基础上新增一个bbs虚拟主机站点。
1 备份配置文件
[root@web01 conf]# pwd /application/nginx/conf [root@web01 conf]# cp nginx.conf{,.oldboy.2017.0819}
2 编辑nginx.conf配置文件,新增bbs虚拟主机站点
[root@web01 conf]# vim nginx.conf.oldboy.20170819 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.etiantian.org; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
新增bbs站点后的nginx.conf配置文件为:
[root@web01 conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.etiantian.org; location / { root html/www; index index.html index.htm; } } server { listen 80; server_name bbs.etiantian.org; location / { root html/bbs; index index.html index.htm; } } }
修改配置文件后,需要建立站点相关文件
[root@web01 conf]# mkdir ../html/{www,bbs} -p #相当于在/application/nginx/html/目录下建立www和bbs两个目录 [root@web01 conf]# echo "www" >../html/www/index.html #在www首页index.html中写入www字母 [root@web01 conf]# echo "bbs" >../html/bbs/index.html #在bbs首页index.html中写入bbs字母
3 nginx配置文件检查语法查看是否有错误:/application/nginx/sbin/nginx -t
[root@web01 conf]# /application/nginx/sbin/nginx -t #自检查看是否有错误 nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
根据提示nginx配置文件检查语法结果成功
4 nginx服务平滑重启
[root@web01 conf]# /application/nginx/sbin/nginx -s reload
apche,nginx等如果平滑重启reload失败那么就用stop和start,禁止用restart
[root@web01 conf]# /application/nginx/sbin/nginx -s stop #stop是带-s stop [root@web01 conf]# /application/nginx/sbin/nginx #start是直接nginx就是start
5 检查nginx服务80端口是否启动
[root@web01 conf]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 5784 root 6u IPv4 23562 0t0 TCP *:http (LISTEN) nginx 5785 www 6u IPv4 23562 0t0 TCP *:http (LISTEN)
6 在linux中验证nginx服务是否可用(当然也可以再windows中验证)
6.1 在管理机m01机器上面本机hosts文件中添加172.16.1.8的dns解析172.16.1.8 web01 www.etiantian.org bbs.etiantian.org
[root@m01 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.1.5 lb01 172.16.1.6 lb01 172.16.1.7 web02 172.16.1.8 web01 www.etiantian.org bbs.etiantian.org 172.16.1.51 de01 db01.etiantian.org 172.16.1.31 nfs01 172.16.1.41 backup 172.16.1.61 m01
6.2 然后ping www.etiantian.org和bbs.etiantian.org看是否可用解析到172.16.1.8这个ip地址。
[root@m01 ~]# ping -c4 www.etiantian.org PING web01 (172.16.1.8) 56(84) bytes of data. 64 bytes from web01 (172.16.1.8): icmp_seq=1 ttl=64 time=0.629 ms 64 bytes from web01 (172.16.1.8): icmp_seq=2 ttl=64 time=0.432 ms 64 bytes from web01 (172.16.1.8): icmp_seq=3 ttl=64 time=0.439 ms 64 bytes from web01 (172.16.1.8): icmp_seq=4 ttl=64 time=0.654 ms --- web01 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 0.432/0.538/0.654/0.105 ms [root@m01 ~]# ping -c4 bbs.etiantian.org PING web01 (172.16.1.8) 56(84) bytes of data. 64 bytes from web01 (172.16.1.8): icmp_seq=1 ttl=64 time=0.896 ms 64 bytes from web01 (172.16.1.8): icmp_seq=2 ttl=64 time=0.459 ms 64 bytes from web01 (172.16.1.8): icmp_seq=3 ttl=64 time=0.782 ms 64 bytes from web01 (172.16.1.8): icmp_seq=4 ttl=64 time=0.445 ms --- web01 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 0.445/0.645/0.896/0.199 ms
6.3 curl 两个虚拟主机站点名字,看是否可用返回对应的www和bbs内容(首页index.html里面的内容)
[root@m01 ~]# curl www.etiantian.org www [root@m01 ~]# curl bbs.etiantian.org bbs
7 windows浏览器中验证
7.1 在windows主机hosts文件中添加dns解析
在C:\Windows\System32\drivers\etc\hosts中添加一条主机解析:
10.0.0.8 www.etiantian.org bbs.etiantian.org
7.2 在浏览器中分别输入www.etiantian.org 和bbs.etiantian.org可以返回对应的首页内容www和bbs,说明新增域名虚拟主机成功。
本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1957720
标签:linux
原文地址:http://sandshell.blog.51cto.com/9055959/1957720