nginx虚拟服务器配置,Nginx虚拟IP主机配置

最简单的虚拟机配置

Http{

Server

{

Listen 80;

Server_name localhost

Access_log logs/default.access.log combined;

Location /{

Index index.html;

Root /data/htdocs/htdocs;

}

}

}

基于IP的虚拟机配置

可以在一块物理网卡上绑定多个ip地址,能够在使用单一网卡的同一个服务器运行多个基于IP的虚拟机

配置多IP方式 IP和主机IP不相同

ifconfig ens33:1 192.168.182.130 broadcast 192.168.182.255

netmask 255.255.255.0 up

route add -host 192.168.182.130 dev ens33:1

ifconfig ens33:2 192.168.182.131 broadcast 192.168.182.255

netmask 255.255.255.0 up

route add -host 192.168.182.131 dev ens33:2

配置重启后就是失效,设置开机启动在 /etc/rc.local添加一下内容

ifconfig ens33:1 192.168.182.130 broadcast 192.168.255 netmask

255.255.255.0 up

route add -host 192.168.182.130 dev ens33:1

ifconfig ens33:2 192.168.182.131 broadcast 192.168.255 netmask

255.255.255.0 up

route add -host 192.168.182.131 dev ens33:2

Nginx 基于ip配置方式

Http{

Server{

Listen 192.168.182.130:80;

Server_name 192.168.182.130;

Access_log logs/server1.access.log combined;

Location /{

Index index.html index.htm;

Root /data/htdocs/server1;

{

}

Server{

Listen 192.168.182.131:80;

Server_name 192.168.182.131;

Access_log logs/server2.access.log combined;

Location /

{

Index index.html index.htm;

Root /data/htdocs/server2;

}

}

}

基于域名的虚拟主机配置

配置dns将ip 映射到正确的IP地址上,配置nginx服务器

配置三台虚拟主机 a.leablogs.com b.leablogs.com www.jindouhui.com

conf配置内容

Http{

Server

{

Listen 80;

Server_name a.leablogs.com

Access_log logs/a.leablogs.com.access.log combined;

Location /

{

Index index.html index.htm;

Root /data/htdocs/a.leablogs.com/;

}

}

Server

{

Listen 80;

Server_name b.leablogs.com

Access_log logs/b.leablogs.com.access.log combined;

Location /

{

Index index.html index.htm;

Root /data/htdocs/b.leablogs.com/;

}

}

Server

{

Listen 80;

Server_name b.leablogs.com leablogs.com *.leablogs.com

Access_log logs/b.leablogs.com.access.log combined;

Location /

{

Index index.html index.htm;

Root /data/htdocs/b.leablogs.com/;

}

}

你可能感兴趣的:(nginx虚拟服务器配置)