Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I bind example.com to be served by the apache, I have running locally on the machine for development purposes?

I tried adding this in my /etc/hosts file 127.0.0.1 example.com

and reloaded apache2 sudo /etc/init.d/apache2 reload but that didn't work.

I have added the virtual hosts for example.com and also enabled it by a2ensite

Edit:

Apache error log (Nothing related as far as I can tell)

[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

Also I try doing wget --spider http://example.com which shows hosts file is doing it work but in browser it opens 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.

Virtual Host Configuration file:

# 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>
share|improve this question
    
Did you add NameVirtualHost *:80 in your default configuration ? In ubuntu, I had to do this to get my virtual host running. Other things go as you say –  sagarchalise Mar 28 '11 at 11:06
    
Yeah! I have added that. –  Ashfame Mar 28 '11 at 11:08
    
try tail -f /var/log/apache2/error_log for viewing error when accessing example.com or you example.com error_log file. may be it will give you some idea. Basically NameVirtualHost *:80 on top of my default file. /etc/apache2/sites-available/example.com for virtual host. sudo a2ensite for enabling it. adding the information to /etc/hosts and sudo service apache2 restart did the work for me –  sagarchalise Mar 28 '11 at 11:20
    
Log file doesn't exist there. Does that mean it is somewhere else or it hasn't been created because no errors were encountered? –  Ashfame Mar 28 '11 at 11:28
    
try ls -l on /var/log/apache2 and see what files exists –  sagarchalise Mar 28 '11 at 11:34

2 Answers 2

If it works with wget, then your server is configured properly and correctly. In all likelihood, your browser is getting name information from other sources in preference to /etc/hosts for some reason.

  • Firstly, check /etc/nsswitch.conf and verify that "files" is listed first under "hosts".

  • Secondly, check your browser configuration, and make sure you aren't using a proxy and that the browser doesn't have a separate way to resolve names separate from the system method (or if it does, that it is configured to use /etc/hosts before DNS).

  • Thirdly, you could set up a different RFC 2606 virtual host (e.g. mysite.example) which is known not to exist in DNS (.example is expressly prohibited), which may foil some causes of naming confusion.

share|improve this answer

Here is my virtual host

<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>

So basically this is for simple php and html script if you need cgi as well you need add to Option AFAIK. So first thing you need is to make $HOME/www/example.com directory. I think the <Directory></Directory> specification are important and you don't have that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.