分享

用Nginx配置虚拟主机

 集微笔记 2013-08-12

Vps 上安装了 nginx。用多个子域名,每个子域名到不同的目录。

如:

  1. http {
  2.     server {
  3.         listen 80;
  4.         server_name a.;
  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.;
  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. }

结果发现用 b. 还是指到 host_a 目录。后来看了官方示例:http://wiki./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. }

加上这个 default 就可使 a. 和 b. 正常工作了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多