我如何绑定 example.com 以由 apache 提供服务,我已经在机器上本地运行以用于开发目的?
我尝试在我的 /etc/hosts 文件中添加它
127.0.0.1 example.com
并重新加载了apache2 sudo /etc/init.d/apache2 reload
,但这没有用。
我已经添加了虚拟主机example.com
并通过以下方式启用了它a2ensite
编辑:
Apache错误日志(据我所知没有相关)
[Mon Mar 28 15:21:01 2011] [notice] Apache/2.2.16 (Ubuntu) configured -- resuming normal operations
[Mon Mar 28 15:21:03 2011] [notice] Graceful restart requested, doing restart
[Mon Mar 28 15:21:03 2011] [notice] Apache/2.2.16 (Ubuntu) configured -- resuming normal operations
[Mon Mar 28 15:21:23 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Mon Mar 28 15:21:23 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Mon Mar 28 15:35:34 2011] [error] [client 127.0.0.1] File does not exist: /var/www/phpmyadmin
[Mon Mar 28 15:36:48 2011] [notice] caught SIGTERM, shutting down
[Mon Mar 28 15:36:49 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 15:49:13 2011] [notice] Graceful restart requested, doing restart
[Mon Mar 28 15:49:13 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 15:49:17 2011] [notice] caught SIGTERM, shutting down
[Mon Mar 28 15:49:18 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 15:50:24 2011] [notice] Graceful restart requested, doing restart
[Mon Mar 28 15:50:24 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 16:15:09 2011] [notice] Graceful restart requested, doing restart
Warning: DocumentRoot [/home/ashfame/www/example.com/] does not exist
(2)No such file or directory: apache2: could not open error log file /home/ashfame/www/example.com/error.log.
Unable to open logs
[Mon Mar 28 16:46:18 2011] [warn] pid file /var/run/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Mon Mar 28 16:46:18 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 16:46:25 2011] [error] [client 127.0.0.1] File does not exist: /var/www/example.com
[Mon Mar 28 16:46:38 2011] [error] [client 127.0.0.1] File does not exist: /var/www/www
[Mon Mar 28 16:55:48 2011] [error] [client 127.0.0.1] File does not exist: /var/www/phpbb/phpbb
[Mon Mar 28 17:17:40 2011] [notice] caught SIGTERM, shutting down
[Mon Mar 28 17:17:41 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Mar 28 17:19:29 2011] [error] [client 127.0.0.1] File does not exist: /var/www/example.com
我也尝试这样做,显示主机文件正在工作,但在浏览器中打开http://www.iana.org/domains/example/wget --spider http://example.com
ashfame@ashfame-desktop:/usr/sbin$ wget --spider http://example.com
Spider mode enabled. Check if remote file exists.
--2011-03-28 17:20:57-- http://example.com/
Resolving example.com... 127.0.0.1
Connecting to example.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
虚拟主机配置文件:
# Place any notes or comments you have here
# It will make any customization easier to understand in the weeks to come
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin [email protected]
ServerName www.example.com
ServerAlias example.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html
DocumentRoot /home/ashfame/www/example.com/
# Custom log file locations
LogLevel warn
ErrorLog /home/ashfame/www/example.com/error.log
CustomLog /home/ashfame/www/example.com/access.log combined
</VirtualHost>
如果它与 wget 一起工作,那么您的服务器配置正确且正确。出于某种原因,您的浏览器很可能会优先从其他来源获取名称信息,而不是 /etc/hosts。
首先,检查
/etc/nsswitch.conf
并确认“文件”列在“主机”下。其次,检查您的浏览器配置,并确保您没有使用代理,并且浏览器没有单独的方法来解析与系统方法分开的名称(或者如果有,它被配置为
/etc/hosts
在 DNS 之前使用)。第三,您可以设置一个不同的 RFC 2606 虚拟主机(例如 mysite.example),它已知在 DNS 中不存在(.example 被明确禁止),这可能会消除一些命名混淆的原因。
这是我的虚拟主机
所以基本上这适用于简单的 php 和 html 脚本,如果您需要 cgi 以及您需要添加到选项 AFAIK。所以你需要做的第一件事是创建 $HOME/www/example.com 目录。我认为
<Directory></Directory>
规范很重要,而您没有。