Как я могу обязать example.com быть врученным апачами, у меня есть выполнение локально на машине в целях разработки?
Я пытался добавить это в своем/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
Также я пытаюсь делать wget --spider http://example.com
который показывает, что файл hosts делает его работа, но в браузере это открывает http://www.iana.org/domains/example/
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 webmaster@example.com
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 явно запрещен), что может помешать некоторым причины путаницы именования.
Вот мой виртуальный хост
<VirtualHost *:80>
ServerName sagar.localhost
ServerAdmin sagar@local
DocumentRoot /home/sagar/www/
<Directory /home/sagar/www>
Options Indexes FollowSymlinks MultiViews
AllowOverride All //for mod_rewrite
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/sagar_error.log
</VirtualHost>
Так что в основном это для простого php и html-скрипта, если вам также нужен cgi, вам нужно добавить в Option AFAIK. Итак, первое, что вам нужно, это создать каталог $ HOME / www / example.com. Я думаю, что спецификация <Directory></Directory>
важна, а у вас ее нет.