zoukankan      html  css  js  c++  java
  • Apache服务器虚拟主机设置问题如何使通过IP访问为默认的apache页面 <转载>

    原文链接:http://www.douban.com/note/28257219/

    这也可以参考解决虚拟主机和宿主主机的同IP不同域名的冲突问题

    ============================================================

    httpd.conf修改的内容为: # Virtual hosts Include conf/extra/httpd-vhosts.conf (去掉注释) httpd-vhosts.conf文件配置如下: NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@www.charity.org DocumentRoot /www/docs/www.charity.org ServerName www.charity.org ServerAlias www.charity.org*. charity.org ErrorLog logs/www.charity.org-error_log CustomLog logs/www.charity.org-access_log common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@www.charity.org DocumentRoot /www/docs/www.test.com/ ServerName www.test.com ErrorLog logs/www.test.com-error_log CustomLog logs/www.test.com-access_log common </VirtualHost> 配置完毕,分别在/www/docs/www.charity.org, /www/docs/www.test.com/,下创建index.html文件。 重起httpd服务: $/usr/local/apache2/bin/apachectl restart 然后访问虚拟主机: http://www.charity.org http://www.test.com 均显示正常,试着通过IP访问,结果出现与http://www.charity.org显示相同的页面。 apache网站解释为当一个请求到达的时候,服务器会首先检查它是否使用了一个能和NameVirtualHost相 匹配的IP地址。如果能够匹配, 它就会查找每个与这个IP地址相对应的<VirtualHost>配置段, 并尝试找出一个ServerName或ServerAlias配置项与请求的主机名相同的。 如果找到了,它就会使用这个服务器的配置。 否则,将使用符合这个IP地址的第一个列出的虚拟主机。 如果要通过IP访问为默认的apache页面 使用下面的配置文件片段,用ip和用两个不同的域名访问会出来的页面都不一样(bumpy在/etc/hosts里就是127.0.0.1): NameVirtualHost * <VirtualHost *> ServerName 127.0.0.1 DocumentRoot /var </VirtualHost> <VirtualHost *> ServerName bumpy DocumentRoot /var/log </VirtualHost> <VirtualHost *> ServerName localhost DocumentRoot /var/www </VirtualHost>
  • 相关阅读:
    GitLab使用公钥SSH key登录
    P1305 新二叉树 /// 二叉树的先序遍历
    P1030 求先序排列 /// 二叉树的遍历
    P1020 导弹拦截 /// DP Dilworth定理 LIS、LDS优化
    USACO 2008 November Gold Cheering up the Cows /// MST oj24381
    USACO 2009 Open Grazing2 /// DP+滚动数组oj26223
    Mid-Atlantic 2008 Lawrence of Arabia /// 区间DP oj21080
    炮兵阵地 /// 状压DP oj26314
    Post Office IOI 2000 /// 区间DP oj24077
    Print Article /// 斜率优化DP oj26302
  • 原文地址:https://www.cnblogs.com/kanone/p/2282753.html
Copyright © 2011-2022 走看看