Nginx 虚拟机如何安装和使用

开发 前端
nginx 虚拟机有不少的问题困扰着我们,首先就是在安装中的问题,下面我们就看看如何才能更好的使用Nginx 虚拟机。

Nginx 虚拟机使用是广大管理员需要掌握的相关问题,在使用中相关的问题需要我们不断学习和掌握,下面我们就详细的看看有关的问题。在Nginx 虚拟机中用多个子域名,每个子域名到不同的目录。

如:

http {   
server {   
listen 80;   
server_name a.chenlb.com;   
access_log logs/a.access.log main;   
server_name_in_redirect off;   
location / {   
index index.html;   
root /home/www/host_a/;   
}   
}   
server {   
listen 80;   
server_name b.chenlb.com;   
access_log logs/b.access.log main;   
server_name_in_redirect off;   
location / {   
index index.html;   
root /home/www/host_b/;   
}   
}   
}   
http {  
server {  
listen 80;  
server_name a.chenlb.com;  
access_log logs/a.access.log main;  
server_name_in_redirect off;  
location / {  
index index.html;  
root /home/www/host_a/;  
}  
}  
server {  
listen 80;  
server_name b.chenlb.com;  
access_log logs/b.access.log main;  
server_name_in_redirect off;  
location / {  
index index.html;  
root /home/www/host_b/;  
}  
}  

  • 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.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.

结果发现用 b.chenlb.com 还是指到 host_a 目录。后来看了官方示例:http://wiki.Nginx.org/NginxVirtualHostExample,提到有个 default 的匹配,如:

http {   
server {   
listen 80 default;   
server_name _;   
access_log logs/default.access.log main;   
server_name_in_redirect off;   
location / {   
index index.html;   
root /var/www/default/htdocs;   
}   
}   
}   
http {  
server {  
listen 80 default;  
server_name _;  
access_log logs/default.access.log main;  
server_name_in_redirect off;  
location / {  
index index.html;  
root /var/www/default/htdocs;  
}  
}  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

加上这个 default 就可使 a.chenlb.com 和 b.chenlb.com 正常工作了。以上就是Nginx 虚拟机的详细介绍。

【编辑推荐】

  1. Nginx设置404相关问题代码答疑
  2. Nginx 502错误两种解决方案介绍
  3. Nginx反向代理的安装和测试的基本流程
  4. Nginx日志在PHP中的优化技巧
  5. Nginx参数站点配置上的问题解决方案


 

责任编辑:张浩 来源: 互联网
相关推荐

2023-06-28 15:53:25

虚拟机Linux

2011-09-15 10:52:09

2022-10-27 12:11:42

VirtualBoxLinux虚拟机

2012-05-18 10:22:23

2009-06-29 19:36:07

虚拟机备份虚拟环境

2011-09-02 18:45:28

2010-07-26 09:02:38

2013-07-17 09:32:58

2014-08-26 14:50:50

NginxApache

2012-04-10 10:29:29

2010-01-13 14:37:39

CentOS VMwa

2009-10-13 15:00:36

物理机虚拟机网络安全

2010-12-23 14:05:12

虚拟机

2016-12-19 13:49:33

2011-09-01 19:20:02

Ubuntu

2009-08-07 11:06:07

虚拟机安装Vista系统

2009-09-07 22:01:52

虚拟机安装Linux系

2013-08-16 11:17:35

虚拟桌面虚拟快照

2014-09-12 14:41:12

2019-07-30 10:14:11

Linuxvirt-manage虚拟机
点赞
收藏

51CTO技术栈公众号