多虚拟主机配置
mkdir /usr/local/nginx/conf.d/
touch /usr/local/nginx/conf.d/devops.conf
sed -n '36,42p' /usr/local/nginx/conf/nginx.conf >
/usr/local/nginx/conf.d/devops.conf
删除nginx.conf中原有的自定义server模块
include /usr/local/nginx/conf.d/*.conf
/usr/local/nginx/sbin/nginx -s reload
基于ip地址的虚拟主机
1在linux系统中添加新的ip地址
ifconfig ens33:1 192.168.71.163
2. 修改nginx.conf中的server模块中的server_name将域名修改为ip地
址
server{
listen 80;
server_name 192.168.71.163;
root /html/devops/;
location / {
index index.html;
}
}
#
server{
listen 80;
server_name 192.168.71.161;
基于端口的虚拟机的配置
1将两个server的ip地址的都修改为相同,监听端口一个设置为80一个设置为8080
/usr/local/nginx/sbin/nginx -s reload
systemctl stop firewalld
访问测试
curl 192.168.81.161:80
curl 192.168.81.161:8080