lanxi256 发表于 2015-8-3 08:21:38

04.12.2011-Apache 配置ServerName linux

  
  http://www.google.com.hk/search?hl=en&source=hp&q=apache+%E4%BA%8C%E7%BA%A7%E5%9F%9F%E5%90%8D+servername&aq=f&oq=&aqi=
  http://www.google.com.hk/search?q=Apache+++%E9%85%8D%E7%BD%AEServerName++linux&hl=en&safe=active&prmd=ivns&ei=2vajTaTSI4j0vQPXtJCICg&start=30&sa=N
  
  http://www.jzxue.com/fuwuqi/linux/201007/05-4032_2.html
  (5)在不同的端口上运行不同的站点(基于多端口的服务器上配置基于域名的虚拟主机):
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080

ServerName www.example1.com
DocumentRoot /www/domain-80


ServerName www.example1.com
DocumentRoot /www/domain-8080


ServerName www.example2.org
DocumentRoot /www/otherdomain-80


ServerName www.example2.org
DocumentRoot /www/otherdomain-8080

(6)基于域名和基于IP的混合虚拟主机的配置:
Listen 80
NameVirtualHost 172.20.30.40

DocumentRoot /www/example1
ServerName www.example1.com


DocumentRoot /www/example2
ServerName www.example2.org


DocumentRoot /www/example3
ServerName www.example3.net

  
  http://www.linuxfly.org/post/542/
  [原]Apache中虚拟主机设置泛域名解析   
大 | 中 | 小
linuxing , 12:04 , 网络服务 » 常见服务 , 评论(0) , 引用(0) , 阅读(1760) , Via 本站原创大 | 中 | 小
    Apache中设置虚拟主机时,ServerName 的设置不支持扩展符,故若需支持泛域名解析,应用ServerAlias 进行配置。
一、原因
通常情况下,虚拟主机中是用ServerName来的设定对应域名的,如下:
引用
# pwd
/etc/httpd/conf/
# cat vhost_domain.conf
# VirtualHost for LinuxFly Test
ServerName mail.linuxfly.org
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/       /var/www/extsuite/extmail/cgi/
Alias /extmail                  /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/      /var/www/extsuite/extman/cgi/
Alias /extman                   /var/www/extsuite/extman/html/
# Suexec config
SuexecUserGroup vuser vgroup
但很多时候,我们设置的Apache虚拟主机可能会接收多个域名的访问请求。例如,mail.linuxfly.org、smtp.linuxfly.org 等都指向同一个虚拟主机,也就是说,当我们访问上述任一域名时,应看到同样的内容(应用本身有对域名限制的除外)。
这时,就应用ServerAlias 增加别名设定。
二、ServerAlias 的配置
1、支持多域名
例如,让mail.linuxfly.org、smtp.linuxfly.org、pop3.linuxfly.org 都指向同一个虚拟主机,可以写成:
引用
ServerName mail.linuxfly.org
ServerAlias smtp.linuxfly.org pop3.linuxfly.org
ServerName 用于指定首选域名,其他的域名用ServerAlias指定,并用空格区分即可。
2、支持泛域名解析
ServerAlias 可支持扩展符,例如,我们希望 linuxfly.org 下的所有二级子域名都能用同一个虚拟主机解析,可以设成:
引用
ServerName mail.linuxfly.org
ServerAlias *.linuxfly.org

保存配置后,记得重新加载apache 配置文件:
# service httpd reload
  
  http://hi.baidu.com/xingyuanju/blog/item/87f6b85008f832648435246b.html
  the first has precedence, perhaps you need a
2008-10-18 14:39
报错信息1:
Starting httpd: VirtualHost 127.0.0.1:80 overl
aps with VirtualHost 127.0.0.1:80, the first has precedence, perhaps you need a
NameVirtualHost directive
这个说明虚拟主机的NAME没开,NameVirtualHost 就是他没开,如下就可以了
#加上这里就好了~~,之后就可加任意多的virtual host了
NameVirtualHost 192.168.8.37:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
#   ServerAdmin webmaster@dummy-host.example.com
#   DocumentRoot /www/docs/dummy-host.example.com
#   ServerName dummy-host.example.com
#   ErrorLog logs/dummy-host.example.com-error_log
#   CustomLog logs/dummy-host.example.com-access_log common
#/VirtualHost>


   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot /var/www/html
   ServerName dummy-host.example.com
   ErrorLog logs/dummy-host.example.com-error_log
   CustomLog logs/dummy-host.example.com-access_log common


   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot /var/www/html
   ServerName XXX.com
   ErrorLog logs/dummy-host.example.com-error_log
   CustomLog logs/dummy-host.example.com-access_log common


Trackback: http://tb.blog.iyunv.com/TrackBack.aspx?PostId=745383
  
  
  
页: [1]
查看完整版本: 04.12.2011-Apache 配置ServerName linux