环境准备

Nginx多虚拟主机_重启

 

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

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

更清晰

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

include  extra/*.conf

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

Nginx多虚拟主机_虚拟主机_02

 

 检查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多虚拟主机_nginx配置_03

 

 Nginx多虚拟主机_配置文件_04

 

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

Nginx多虚拟主机_nginx_05

 

 环境准备

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

 服务器端的nginx配置

Nginx多虚拟主机_重启_06

 

 

Nginx多虚拟主机_虚拟主机_07

 

 

 

 重启nginx

nginx -s stop 

nginx

 Nginx多虚拟主机_配置文件_08

 

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

Nginx多虚拟主机_虚拟主机_09