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 虚拟机的详细介绍。

分享文章:Nginx虚拟机如何安装和使用
文章出自:http://www.mswzjz.cn/qtweb/news19/235769.html

攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能