How do I remove a duplicate IP virtual host from httpd.conf?

gareth.star

Member
May 9, 2013
24
2
53
cPanel Access Level
Root Administrator
Hi,

I have a domain (example.com) which points to 123.456.789.012. If I visit Example Domain, everything is fine. My problem occurs when I try to visit http://123.456.789.012/. I expect to see the same content as visiting example.com directly but instead I am redirected to http://123.456.789.012/cgi-sys/defaultwebpage.cgi and am shown the default cPanel/Apache page.

I have checked /etc/httpd/conf/httpd.conf and see:

Code:
NameVirtualHost 123.456.789.012:80

<VirtualHost 123.456.789.012:80>
    ServerName server.example.com
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin [email protected]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
</VirtualHost>

<VirtualHost *>
    ServerName server.example.com
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin [email protected]
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
</VirtualHost>

<VirtualHost 123.456.789.012:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /home/example/public_html
    ServerAdmin [email protected]
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/example.com combined
    CustomLog /usr/local/apache/domlogs/example.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    ## User example # Needed for Cpanel::ApacheConf
    UserDir enabled example
    <IfModule mod_suphp.c>
        suPHP_UserGroup example example
    </IfModule>
    <IfModule !mod_disable_suexec.c>
        <IfModule !mod_ruid2.c>
            SuexecUserGroup example example
        </IfModule>
    </IfModule>
    <IfModule mod_ruid2.c>
        RMode config
        RUidGid example example
    </IfModule>
    ScriptAlias /cgi-bin/ /home/example/public_html/cgi-bin/


    # To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/std/2/example/example.com/*.conf"

</VirtualHost>
The obvious problem is that there are 2 VirtualHost's pointing for 123.456.789.012:80.
I have searched everywhere but I don't know what or where I am meant to modify in order for the first VirtualHost (the one pointing to /usr/local/apache/htdocs) to be removed.
As a test, I edited the httpd.conf file manually and removed that VirtualHost and restarted Apache. I was then able to access http://123.456.789.012/ and see the site, as expected.

I ran "/usr/local/cpanel/bin/apache_conf_distiller --update" and "/usr/local/cpanel/bin/build_apache_conf" and as before, the bad VirtualHost returned.

Does anyone know where in cPanel or WHM I am meant to go, or what files I need to edit on the filesystem, to remove this bad VirtualHost?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello :)

You can try rebuilding the Apache configuration file via:

Code:
/scripts/rebuildhttpdconf
If the issue persists, could you check to see if any third-party applications are installed (e.g. Nginx, LiteSpeed) that could be altering the Apache configuration after you modify it?

Thank you.
 

gareth.star

Member
May 9, 2013
24
2
53
cPanel Access Level
Root Administrator
Hi :)

Unfortunately rebuilding the file didn't work. It displayed the following:

Code:
info [rebuildhttpdconf] Missing owner for domain server.example.com, force lookup to root
info [rebuildhttpdconf] Domain ownership conflict detected for example.com, users nobody, example
Built /usr/local/apache/conf/httpd.conf OK
While I would like to fix both of those messages, I think it's the second that is causing the problem.

I don't think I'm running anything that would interfere with the conf files... well, not that I can think of.

Thanks for the quick reply!
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,607
80
458
cPanel Access Level
Root Administrator
I'm guessing server.example.com is the server hostname. Is that correct?

How are you wanting to handle requests to the server hostname?

If it's a matter of changing the IP address for the server hostname VirtualHost, then you can do that in 'Basic cPanel & WHM Setup' within WHM.
 

gareth.star

Member
May 9, 2013
24
2
53
cPanel Access Level
Root Administrator
Yes, server.example.com is the hostname.

If possible, I'd like requests to the hostname to point to the site as well. ie. server.example.com should show the same content as example.com

The IP address in "Basic cPanel & WHM Setup" is already set to the IP address of the server.

Thanks for the reply! :)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
You should not configure your hostname as an account on the server or as a domain name associated with an account. This is not supported, and can result in Apache configuration problems. You could use a separate IP address for the account if you want it's content to load on that IP address. Or, you can manually modify the Apache configuration file, positing the VirtualHost for the account as the first entry for the IP address. Documentation on how to preserve changes to the httpd.conf file can be found at:

Apache Configuration Changes

Thank you.
 

gareth.star

Member
May 9, 2013
24
2
53
cPanel Access Level
Root Administrator
I don't have the hostname as an account. I was just saying that it would be nice if the hostname URL could be resolved too, but it's not a big deal if it doesn't. My concern still lies with the IP address URL.

I'll look at the link given.

Thanks again for the help :)