Nginx 虚拟机如何安装和使用

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

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

如:

  1. http {   
  2. server {   
  3. listen 80;   
  4. server_name a.chenlb.com;   
  5. access_log logs/a.access.log main;   
  6. server_name_in_redirect off;   
  7. location / {   
  8. index index.html;   
  9. root /home/www/host_a/;   
  10. }   
  11. }   
  12. server {   
  13. listen 80;   
  14. server_name b.chenlb.com;   
  15. access_log logs/b.access.log main;   
  16. server_name_in_redirect off;   
  17. location / {   
  18. index index.html;   
  19. root /home/www/host_b/;   
  20. }   
  21. }   
  22. }   
  23. http {  
  24. server {  
  25. listen 80;  
  26. server_name a.chenlb.com;  
  27. access_log logs/a.access.log main;  
  28. server_name_in_redirect off;  
  29. location / {  
  30. index index.html;  
  31. root /home/www/host_a/;  
  32. }  
  33. }  
  34. server {  
  35. listen 80;  
  36. server_name b.chenlb.com;  
  37. access_log logs/b.access.log main;  
  38. server_name_in_redirect off;  
  39. location / {  
  40. index index.html;  
  41. root /home/www/host_b/;  
  42. }  
  43. }  

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

  1. http {   
  2. server {   
  3. listen 80 default;   
  4. server_name _;   
  5. access_log logs/default.access.log main;   
  6. server_name_in_redirect off;   
  7. location / {   
  8. index index.html;   
  9. root /var/www/default/htdocs;   
  10. }   
  11. }   
  12. }   
  13. http {  
  14. server {  
  15. listen 80 default;  
  16. server_name _;  
  17. access_log logs/default.access.log main;  
  18. server_name_in_redirect off;  
  19. location / {  
  20. index index.html;  
  21. root /var/www/default/htdocs;  
  22. }  
  23. }  

加上这个 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

2013-07-17 09:32:58

2014-08-26 14:50:50

NginxApache

2010-07-26 09:02:38

2012-04-10 10:29:29

2009-10-13 15:00:36

物理机虚拟机网络安全

2010-12-23 14:05:12

虚拟机

2010-01-13 14:37:39

CentOS VMwa

2016-12-19 13:49:33

2011-09-01 19:20:02

Ubuntu

2009-09-07 22:01:52

虚拟机安装Linux系

2009-08-07 11:06:07

虚拟机安装Vista系统

2013-08-16 11:17:35

虚拟桌面虚拟快照

2014-09-12 14:41:12

2019-07-30 10:14:11

Linuxvirt-manage虚拟机
点赞
收藏

51CTO技术栈公众号