搭建nginx虚拟主机——基于域名、端口和IP
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,nginx支持的虚拟主机有三种1、基于域名的虚拟主机2、基于IP的虚拟主机3、基于端口的虚拟主机一、基于域名构建1、编译安装nginx服务2、配置DNS域名解析服务3、配置虚拟主机a、创建自测网页[r
千家信息网最后更新 2025年12月02日搭建nginx虚拟主机——基于域名、端口和IP
nginx支持的虚拟主机有三种
1、基于域名的虚拟主机
2、基于IP的虚拟主机
3、基于端口的虚拟主机
一、基于域名构建
1、编译安装nginx服务
2、配置DNS域名解析服务
3、配置虚拟主机
a、创建自测网页
[root@localhost named]# cd [root@localhost ~]# mkdir -p /var/www/html/kgc[root@localhost ~]# mkdir -p /var/www/html/accp[root@localhost ~]# ls /var/www/html/accp kgc[root@localhost ~]# cd /var/www/html/[root@localhost html]# echo "this kgc web" > kgc/index.html[root@localhost html]# echo "this accp web" > accp/index.html
b、编辑nginx.conf配置文件
vim /usr/local/nginx/conf/nginx.conf include conf.d/*.conf; server { listen 80; server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log ; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log ; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }c、重载服务
systemctl restart nginxnetstat -ntap | grep 80
d、访问测试
www.kgc.comwww.accp.com
二、基于端口
a、创建另一个端口的测试网页
[root@localhost ~]# cd /var/www/html/[root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html
b、编辑nginx.conf配置文件,仅修改监听地址
server { listen 192.168.109.137:80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log ; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 192.168.109.137:8080; server_name www.accp.com; charset utf-8; access_log logs/www.accp8080.com.access.log ; location / { root /var/www/html/accp8080; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }c、重载nginx服务
systemctl restart nginxnetstat -ntap | grep 80
d、测试网页
www.accp.comwww.accp.com8080
三、基于IP
1、修改网页配置文件中的区域数据配置文件
vim /var/named/kgc.com.zonesystemctl restart named
2、编辑nginx.conf中的配置,修改ip地址
server { listen 192.168.109.137:80; server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log ; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 192.168.109.134:80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log ; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }c、重载nginx服务
systemctl restart nginxnetstat -ntap | grep 80
d、测试网页
192.168.109.137192.168.109.134
配置
主机
虚拟主机
网页
服务
文件
测试
域名
端口
地址
区域
数据
支持
监听
编译
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
台州app软件开发流程八个步骤
达内软件开发在线培训
大内存 服务器
广州美菜网络技术有限公司
数据库在云服务器的作用
万方数据库与知网数据库
access 网站数据库
灵盾网络技术有限公司
乐享网络技术有限公司深圳
网站数据库服务器放在dmz去吗
宿州软件开发培训学费
元数据库访问失败
联盟怎么给不同服务器邮寄
为什么螃蟹游戏没有服务器
每天几千万流量需要多大服务器
局域网服务器打印机驱动
数据库经常使用的函数
PS5登录B站连不上服务器
网络安全法信息泄露责任
浙江成功软件开发
软件开发游戏公司公司
网络安全在线测试
宝德服务器前面维修口ip和密码
c 访问数据库超时时间
朝阳区先进软件开发要求
商品运营信息软件开发
互联网软件开发工程师月薪是多少
数据库导数据工具免费完整版
配置前置管理端口服务器
餐厅采购数据库管理系统