centos 6 - Why my local website display Apache2 Test Page

14
2014-03
  • Tấn Triển Nguyễn

    I've installed httpd, mysql and php on my CentOS 6.4 server. I've setup Virtual host 80 and 443 for trien.abc

    My client (windows 7) still displays Apache2 test page. Where did I go wrong?

    My Apache config file containing the VirtualHost definition is located in: /etc/httpd/vhosts/common/trien.conf:

    <VirtualHost *:80>
      DocumentRoot /var/www/vhosts/testing.page
      ServerName trien.abc
      ServerAlias trien.abc
      ErrorLog /var/log/httpd/trien.error.log common
      LogFormat "%v %h %l %u %t \"%r\" %>s %b %f" common
      CustomLog /var/log/httpd/trien.access.log common
      AddDefaultCharset UTF-8
    
      <Directory "/var/www/vhosts/testing.page">
        AllowOverride All
        Allow from all
        Options -Indexes
      </Directory>
    </VirtualHost>
    

    The DocumentRoot /var/www/vhosts/testing.page just has one file: index.html. The contents of the file is "Welcome, trien".

    It can't display the contents of the file, instead it displays the Apache2 test page.

    Could you please help me?

  • Answers
  • Unnikrishnan

    This could happen because of many reasons..Some of the possible reasons are the following

    • Check the selinux context of the index file. Try loading the page after setting selinux to permissive.

    • Check permissions of the index file. It should be readable to others

    • Have you restarted httpd after making changes?

      .

    • Check the DirecoryIndex in your httpd.conf. In your case, it must be

    DirectoryIndex index.html

    Please check your errorlog. paste it here if you cant troubleshoot.

  • Journeyman Geek

    You haven't updated your index.html/index.php or more accurately where you go when you go to the root of your seite - the stock one Apache 2 is the 'test' page. Update your document root to the appropriate location and it should work.

    Don't forget to enable the virtualhosts and restart apache.


  • Related Question

    Apache2 2.2.14 setup with multiple virtual hosts for local testing
  • Phill Pafford

    I have setup an Apache 2 virtual host by this method.

    under /etc/apache2/sites-available I've create a dummy_site_1.conf

    dummy_site_1.conf

    <VirtualHost local.dummy_site_1:80>
        ServerName local.dummy_site_1
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/dummy_site_1
        ErrorLog /var/log/apache2/dummy_site_1__error.log
        TransferLog /var/log/apache2/dummy_site_1__access.log
        <Directory /var/www/dummy_site_1>
            AllowOverride Options Limit None
            Options -Indexes FollowSymLinks
        Order deny,allow
        Allow from all
        </Directory>
        DirectoryIndex index.php
        #DISABLE HTTP TRACE
        #RewriteEngine On
        #RewriteCond %{REQUEST_METHOD} ^TRACE
        #RewriteRule .* - [F]
    </VirtualHost>
    

    I also added this line the the httpd.conf:

    ServerName local.dummy_site_1
    

    Now all is working with this setup, I type local.dummy_site_1 in the URL and I can see my site.

    The problem is when I try to add another site config dummy_site_2.conf and create about the same settings

    dummy_site_2.conf

    <VirtualHost local.dummy_site_2:80>
        ServerName local.dummy_site_2
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/dummy_site_2
        ErrorLog /var/log/apache2/dummy_site_2__error.log
        TransferLog /var/log/apache2/dummy_site_2__access.log
        <Directory /var/www/dummy_site_2>
            AllowOverride Options Limit None
            Options -Indexes FollowSymLinks
        Order deny,allow
        Allow from all
        </Directory>
        DirectoryIndex index.php
        #DISABLE HTTP TRACE
        #RewriteEngine On
        #RewriteCond %{REQUEST_METHOD} ^TRACE
        #RewriteRule .* - [F]
    </VirtualHost>
    

    I also added this line the the httpd.conf:

    ServerName local.dummy_site_2
    

    I get this error:

    user@host:/etc/apache2$ sudo /etc/init.d/apache2 restart
     * Restarting web server apache2                                                                                                                                                                     [Wed Sep 15 14:00:43 2010] [error] (EAI 5)No address associated with hostname: Could not resolve host name local.dummy_site_2 -- ignoring!
     ... waiting [Wed Sep 15 14:00:44 2010] [error] (EAI 5)No address associated with hostname: Could not resolve host name local.dummy_site_2 -- ignoring!
    

    Why? am I configuring this wrong?


  • Related Answers
  • Linker3000

    You don't need 'ServerName local.dummy_site_2' in httpd.conf so take that out, but add this instead:

    NameVirtualHost ip-address-of-server:80
    

    eg: NameVirtualHost 192.168.1.10:80

    Once you have made the change you will need to restart Apache.

    If things still do not work as expected, add a line to each of your virtualhost conf files below the servername lines so they look like this:

    ServerName local.dummy_site_1
    ServerAlias *.local.dummy_site_1 local.dummy_site_1
    

    and

    ServerName local.dummy_site_2
    ServerAlias *.local.dummy_site_2 local.dummy_site_2
    

    Again, restart Apache to check out the changes.

    EDIT: Silly me - just spotted the other bit of the problem - ALL of your VirtualHost declarations should use the IP address of the virtual server - eg:

    <VirtualHost 192.168.1.10:80>
    
  • Carl Vancil

    Actually, you can remove the IP address and or site name altogether.

    example:

    NameVirtualHost *:80
    NameVirtualHost *:443
    
    <VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/path/to/vhost/documents"
    ServerName servername.domain.tld
    ServerAlias serveralias.domain.tld
    ErrorLog "/path/to/logfiles/servername.domain.tld-error.log"
    CustomLog "/path/to/logfiles/servername.domain.tld-access.log" common
    <Directory "/path/to/vhost/documents">
    allow from all
    Option +Indexes
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:443>
    ServerAdmin [email protected]
    DocumentRoot "/path/to/vhost/documents"
    ServerName servername.domain.tld
    ServerAlias serveralias.domain.tld
    SSLEngine On
    SSLCertificateFile /path/to/certificate/file.cert
    SSLCertificateKeyFile /path/to/certificate/file.key
    ErrorLog "/path/to/logfiles/servername.domain.tld-error.log"
    CustomLog "/path/to/logfiles/servername.domain.tld-access.log" common
    <Directory "/path/to/vhost/documents">
    allow from all
    Option +Indexes
    </Directory>
    </VirtualHost>
    

    (Now, lets do an example of vhost combined with mod_proxy; ip=numeric-octet, below)

    <VirtualHost *:80>
    ProxyPreserveHost Off
    ProxyPass / http://ip.ip.ip.ip/
    ProxyPassReverse / http://ip.ip.ip.ip/
    ServerName servername.domain.tld
    </VirtualHost>
    

    Basically, so long as your DNS info matches up with the vhosts you configure, then it should all work.