ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 分类 1. 基于多IP的虚拟主机; 2. 基于多端口的虚拟主机(同域名多个端口); 3. 基于域名的虚拟主机(不同域名对应不同虚拟主机); ## 多IP虚拟主机 在一台有多个网卡的机器上使用多个server段,然后配置不同的IP地址即可; ``` http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 192.168.10.101; server_name localhost; charset utf-8; location / { root html/server1; index index.html index.htm; } } server { listen 192.168.10.102; server_name localhost; charset utf-8; location / { root html/server2; index index.html index.htm; } } server { listen 192.168.10.103; server_name localhost; charset utf-8; location / { root html/server3; index index.html index.htm; } } } ``` ## 多端口虚拟主机 同一台机器,同一个IP,配置多个不同端口的虚拟主机; ``` http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8081; server_name localhost; charset utf-8; location / { root html/server1; index index.html index.htm; } } server { listen 8082; server_name localhost; charset utf-8; location / { root html/server2; index index.html index.htm; } } } ``` ## 多域名虚拟主机 ``` http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; //不用写IP地址 server_name sina.com; //填写域名 charset utf-8; location / { root html/server1; index index.html index.htm; } } server { listen 80; server_name baidu.com; charset utf-8; location / { root html/server2; index index.html index.htm; } } } ```