0
点赞
收藏
分享

微信扫一扫

nginx 配置基于ip的虚拟主机

janedaring 2022-04-22 阅读 75

1.手动在ens33中设置多个IP(要与自己的IP地址网段相同)

[root@localhost ~]# ifconfig ens33:1 192.168.90.11 netmask 255.255.255.0 up
[root@localhost ~]# ifconfig ens33:2 192.168.90.12 netmask 255.255.255.0 up
[root@localhost ~]# ifconfig //查看ip设置效果

2.IP地址添加成功,因为服务器重启后将会失效,我们需要将上述命令写入到自动启动脚本文件rc.local

[root@localhost ~]# echo "ifconfig ens33:1 192.168.90.11">>/etc/rc.local
[root@localhost ~]# echo "ifconfig ens33:2 192.168.90.12">>/etc/rc.local
[root@localhost ~]# cat /etc/rc.local

3.配置ip虚拟主机

[root@localhost ~]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf

添加以下代码:

server{
listen 80;
server_name 192.168.90.11; // 你添加的ip地址
location / {
root /www/web;
index index.html index.htm;
}
}
server{
listen 80;
server_name 192.168.90.12; // 你添加的ip地址
location / {
root /www/blog;
index index.html index.htm;
}
}

//保存退出
[root@localhost conf]# /usr/local/nginx/sbin/nginx -t //检查语法错误
[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload //重启服务

4.测试是否成功:在浏览器中输入http://自己添加的IP地址:80

http://192.168.90.11:80

 

http://192.168.90.12:80

 

 

举报

相关推荐

0 条评论