一、基于域名构建
1、编译安装nginx服务
2、配置DNS域名解析服务
3、配置虚拟主机
a、创建自测网页
?
|
1
2
3
4
5
6
7 |
[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配置文件
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
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、重载服务
?
|
1
2 |
systemctl restart nginx
netstat -ntap | grep 80 |
d、访问测试
www.kgc.com
www.accp.com
二、基于端口
a、创建另一个端口的测试网页
?
|
1
2 |
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html |
b、编辑nginx.conf配置文件,仅修改监听地址
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
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服务
?
|
1
2 |
systemctl restart nginx
netstat -ntap | grep 80 |
d、测试网页
www.accp.com
www.accp.com8080
三、基于IP
1、修改网页配置文件中的区域数据配置文件
?
|
1
2 |
vim /var/named/kgc.com.zone
systemctl restart named |
2、编辑nginx.conf中的配置,修改ip地址
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
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服务
?
|
1
2 |
systemctl restart nginx
netstat -ntap | grep 80 |
d、测试网页
?
|
1
2 |
192.168.109.137
192.168.109.134 |
总结
以上所述是小编给大家介绍的基于域名、端口和IP搭建nginx虚拟主机,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
原文链接:https://blog.51cto.com/14475876/2449830
相关文章
猜你喜欢
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 43
-
2025-06-04 74
-
2025-05-29 20
-
2025-05-25 74
-
2025-06-05 71
热门评论

