4-Ngnix配置基于域名的多虚拟主机
  wwLZeziuqjLR 2023年11月02日 16 0


Nginx配置文件在/usr/local/nginx/conf下,文件名为nginx.conf

1.Ngnix配置基于域名的多虚拟主机

-->进入/usr/local/nginx/conf目录

命令:

cd /usr/local/nginx/conf

pwd

[root@cent79-2 conf]# cd /usr/local/nginx/conf/
[root@cent79-2 conf]# pwd
/usr/local/nginx/conf
[root@cent79-2 conf]#

-->编辑nginx.conf

命令:

vi nginx.conf

4-Ngnix配置基于域名的多虚拟主机_nginx

-->在/usr/local/nginx/html目录下,创建ztj和ztj1目录,并创建测试html文件

命令:

mkdir ztj
mkdir ztj1
echo "I am itztj" > ztj/index.html
echo "I am itxiaohei" > ztj1/index.html

[root@cent79-2 html]# mkdir ztj
[root@cent79-2 html]# mkdir ztj1
[root@cent79-2 html]# echo "I am itztj" > ztj/index.html
[root@cent79-2 html]# echo "I am itztj1" > ztj1/index.html
[root@cent79-2 html]# ls
50x.html  index.html  ztj  ztj1
[root@cent79-2 html]# cd ztj
[root@cent79-2 ztj]# pwd
/usr/local/nginx/html/ztj
[root@cent79-2 ztj]# cat index.html 
I am itztj
[root@cent79-2 ztj]# cd ../ztj1/
[root@cent79-2 ztj1]# cat index.html 
I am itxiaohei
[root@cent79-2 ztj1]#

-->编辑/etc/hosts,添加地址映射

4-Ngnix配置基于域名的多虚拟主机_html_02

-->宿主机添加地址映射

4-Ngnix配置基于域名的多虚拟主机_html_03

命令:

nginx -t

[root@cent79-2 etc]# nginx -t
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@cent79-2 etc]#

-->重新加载nginx

命令:

nginx -s reload

[root@cent79-2 etc]# nginx -s reload
[root@cent79-2 etc]# ps -ef |grep nginx
root       1435      1  0 09:56 ?        00:00:00 nginx: master process nginx
nginx      1438   1435  0 09:56 ?        00:00:00 nginx: worker process
root       1441   1239  0 09:56 pts/0    00:00:00 grep --color=auto nginx
[root@cent79-2 etc]# netstat -antulp |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1435/nginx: master  
udp        0      0 0.0.0.0:68              0.0.0.0:*                           807/dhclient        
[root@cent79-2 etc]#

-->验证

->http://www.itztj.com

4-Ngnix配置基于域名的多虚拟主机_nginx_04

->http://www.itxiaohei.com

4-Ngnix配置基于域名的多虚拟主机_地址映射_05

 至此,Ngnix基于域名的多虚拟主机配置也就结束了。


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: Linux下安装部署MySQL 下一篇: ospf基础配置
  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  P3nxyT0LRuwj   2023年11月28日   26   0   0 nginxhtmlWeb
  jnZtF7Co41Wg   2023年12月11日   31   0   0 nginx客户端服务端
  jnZtF7Co41Wg   2023年11月28日   21   0   0 nginx文件名linux命令
  stLBpDewCLT1   2023年12月08日   30   0   0 nginx
  jnZtF7Co41Wg   2023年12月10日   22   0   0 nginx客户端服务端NFS
  eHipUjOuzYYH   2023年12月06日   29   0   0 nginxHTTP
  eHipUjOuzYYH   2023年12月06日   26   0   0 nginx加载IPV6