439 words
2 minutes
nginx虚拟主机是什么(nginx虚拟主机讲解) – -
2025-11-11
No Tags

tags: [] tags: []

同时发布两个网站: DocumentRoot /usr/local/nginx/html/web1 DocumentRoot /usr/local/nginx/html/web2 2 基于IP的虚拟主机 应用场景:IP充足的环境 server { listen 192.168.11.251:80; location / { root html/web1; index index.html index.htm index.php; }}server { listen 192.168.11.252:80;location / { root html/web2; index index.html index.htm; }} 基于IP的虚拟主机特点 不同IP对应不同网站 访问方便,用户直接使用默认端口即可访问 服务器需要有多个IP地址(一个公网IP大概一年的费用是600左右) 维护方便,基于独立IP的站点,便于监控、维护。 3 基于端口的虚拟主机 #只需要一个IP #缺点 端口你是无法告诉公网用户 无法适用于公网客户 适合内部用户 基于端口 server { listen 80; #server_name www.abc.com; location / { root html/web1; index index.html index.htm index.php; }}server { listen 8080; #server_name www.abc.com; location / { root html/web2; index index.html index.htm; }} 基于端口的虚拟主机特点 不同端口对应不同网站 访问需要加端口 节省IP地址 适合私网运行 4 基于域名的虚拟主机 #一个网站必然有一个域名 基于域名 server { listen 80; server_name web1.a.com; location / { root html/web1; index index.html index.htm index.php; }}server { listen 80; server_name web2.b.com; location / { root html/web2; index index.html index.htm; }} 基于域名的虚拟主机特点 不同域名对应不同网站 需要多个域名 可以是二级或三级域名 每个站点使用默认端口,方便用户访问 只需要一个IP地址,节约成本 适合公网环境 总结 什么是虚拟主机 虚拟主机的作用 虚拟主机如何实现 重点:不同类型虚拟主机的作用,如何实现 难点:虚拟主机实现的形式 , ,

nginx虚拟主机是什么(nginx虚拟主机讲解) – -
https://fuwari.vercel.app/posts/post_54/
Author
Lorem Ipsum
Published at
2025-11-11
License
CC BY-NC-SA 4.0