为 Apache 默认文件提供服务的所有虚拟主机

TJ *_*J L 5 linux ubuntu apache-2.2

我正在尝试将 Apache 配置为网络内网络服务器,并且正在使用站点可用/站点启用功能,而不仅仅是静态虚拟主机文件。我设置了几个 VirtualHosts,它们都有一个唯一的 DocumentRoot,但是对所有 VirtualHosts 的请求只是提供“它正在工作!” 默认文件。我一生都无法弄清楚为什么它不会从正确的目录中提供内容。这是 virtualhost 指令文件的内容,如果我需要发布更多内容,请告诉我。

default(请注意,apache 将其重命名为000-defaultin sites-enabled,因此这不是排序问题)

NameVirtualHost *:80
ServerName emp

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 ServerName emp
 DocumentRoot /var/www

 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

billmed

<VirtualHost *:80>
 ServerName billmed.emp
 ServerRoot /home/empression/Projects/billmed/web/httpdocs

 <Directory "/home/empression/Projects/billmed/web/httpdocs">
  Order Allow,Deny
  Allow from All
 </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

请注意,我有两个DNS区域emp,并billmed.emp在/ etc / hosts文件,以及条目。我的最终目标是将这台机器设置为具有自定义 tld (emp) 的内部网络服务器,但进展非常缓慢。

更多信息

/etc/hosts 条目

#custom-sites
192.168.1.100 emp
192.168.1.100 billmed.emp
Run Code Online (Sandbox Code Playgroud)

ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

#NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>
Run Code Online (Sandbox Code Playgroud)

ls -l sites-enabled

empression@empression-server1:/etc/apache2/sites-available$ ls -l ../sites-enabled/
total 0
lrwxrwxrwx 1 root root 26 2010-05-22 12:36 000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 26 2010-05-22 13:33 billmed -> ../sites-available/billmed
Run Code Online (Sandbox Code Playgroud)

更新 2010-06-16

我有几个星期没能解决这个问题,但到目前为止我已经尝试了下面发布的所有解决方案,但仍然无法解决问题,所以我增加了赏金。

更新

这是输出 apache2ctl -t -D DUMP_VHOSTS

empression@empression-server1:~$ apache2ctl -t -D DUMP_VHOSTS
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Mon Jul 12 14:29:01 2010] [warn] NameVirtualHost 127.0.0.1:80 has no VirtualHosts
VirtualHost configuration:
192.168.1.100:80       is a NameVirtualHost
         default server billmed.emp (/etc/apache2/sites-enabled/billmed:1)
         port 80 namevhost billmed.emp (/etc/apache2/sites-enabled/billmed:1)
Syntax OK
Run Code Online (Sandbox Code Playgroud)

ris*_*sin 8

在虚拟主机定义文件中,更正下面的行。

ServerRoot /home/empression/Projects/billmed/web/httpdocsDocumentRoot /home/empression/Projects/billmed/web/httpdocs

使用 DocumentRoot 指令为虚拟主机提供服务。这里是更多信息的链接 http://httpd.apache.org/docs/2.2/mod/core.html


更新您的虚拟主机定义(/etc/apache2/sites-enabled/billmed)如下,

<虚拟主机 *:80>
 服务器名称 billmed.emp
 DocumentRoot /home/empression/Projects/billmed/web/httpdocs

 <目录“/home/empression/Projects/billmed/web/httpdocs”>
  订单允许,拒绝
  所有人都允许
 </目录>
</虚拟主机>


pjz*_*pjz 5

@yasin 是正确的;你需要让你的 VirtualHosts 指定一个DocumentRoot('...httpd 将提供文件的目录...')而不是一个ServerRoot('...服务器所在的目录。通常它会包含子目录 conf / 和日志/....')

有可能是另外一个问题,但是这部分肯定是不对的。


Cas*_*der 2

/etc/hostsDNS 配置中的映射是什么?尝试替换*127.0.0.1我的意思<VirtaulHost 127.0.0.1:80>是和NameVirtualHost 127.0.0.1:80。你的里面有什么/etc/apache2/ports.conf?检查所有符号链接是否就位。例如:/etc/apache2/sites-enabled/<yoursite.emp>

编辑:

试试这个: 在ports.conf

NameVirtualHost 127.0.0.1:80
Listen 127.0.0.1:80

NameVirtualHost 192.168.1.100:80
Listen 192.168.1.100:80
Run Code Online (Sandbox Code Playgroud)

然后在000-default<VirtualHost 127.0.0.1:80>billmed<VirtualHost 192.168.1.100:80