Nginx多虚拟主机

环境准备

 

 添加nginx的配置,添加多个server{}标签,让nginx支持基于ip的多虚拟主机,返回多个站点内容

给nginx添加include包含语法,让其他目录下的配置文件参数,导入到nginx.conf中,这样的写法,能够让nginx每一个配置文件,看起来更简洁

更清晰

修改nginx.conf,在http{}标签中的最后一行,添加如下参数,extra文件夹和nginx.conf文件夹为相对

include  extra/*.conf

在extra目录下,添加多个基于ip的虚拟主机配置

 

 检查nginx语法是否正确

[root@localhost extra]# nginx -t
nginx: the configuration file /opt/nginx1.8/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx1.8/conf/nginx.conf test is successful

重新加载nginx 配置,改了较多的nginx配置,在允许重启的情况下

 

nginx -s  stop

准备站点内容

 

 

 

Nginx基于多域名的虚拟主机配置

 

 环境准备

在客户端本地修改hosts文件信息

 服务器端的nginx配置

 

 

 

 

 

 重启nginx

nginx -s stop 

nginx

 

 

 nginx支持基于多端口的虚拟主机配置

 

posted on 2021-07-29 23:22  sprr  阅读(68)  评论(0编辑  收藏  举报