我正在尝试将 Apache 配置为网络内 Web 服务器,并使用 sites-available/sites-enabled 功能,而不是仅使用静态 vhost 文件。我设置了几个 VirtualHost,它们都具有唯一的 DocumentRoot,但是对所有 VirtualHost 的请求都只提供“正在运行!”默认文件。我无论如何也想不出为什么它不能从正确的目录中提供内容。以下是 virtualhost 指令文件的内容,如果我需要发布更多信息,请告诉我。
default
(请注意,apache 将其重命名为000-default
在站点启用的,因此这不是排序问题)
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>
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>
emp
请注意,我有和的 DNS 区域billmed.emp
,以及 /etc/hosts 中的条目。我的最终目标是将这台机器设置为具有自定义顶级域名 (emp) 的内部 Web 服务器,但进展相当缓慢。
更多信息
/etc/hosts
条目
#custom-sites
192.168.1.100 emp
192.168.1.100 billmed.emp
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>
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
更新 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
答案1
在虚拟主机定义文件中,更正下面的行。
ServerRoot /home/empression/Projects/billmed/web/httpdocs
到
DocumentRoot /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”> 订单允许、拒绝 允许所有人 </目录> </虚拟主机>
答案2
答案3
/etc/hosts
您的DNS 配置中的 或 中的映射是什么?尝试*
用替换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
然后在000-default
:<VirtualHost 127.0.0.1:80>
在billmed
:<VirtualHost 192.168.1.100:80
答案4
更改服务器根目录到文档根目录在比尔梅德文件。
添加/移动您的比尔梅德/etc/apache2/sites-available/ 中的 vhost 配置。
然后启用比尔梅德虚拟主机如下:
sudo a2ensite billmed
重新启动apache:
sudo service apache2 restart
编辑:将 a2enmod 改为 a2ensite,愚蠢的打字错误 : )