Question
How do I set a default VirtualHost for each IP address?
Answer
If you have a domain that resolves to an IP address on a server but doesn't exist on the server, Apache serves the content for the first site bound to the IP address to which the domain resolves. You can read more about this here:
Secondary shared IP address shows a website
To change this behavior, you need to add a new VirtualHost to /etc/apache2/conf.d/includes/pre_virtualhost_global.conf that will become the first VirtualHost.
Warning: Creating a custom VirtualHost could potentially cause unexpected behavior. These changes should only be made if you can troubleshoot VirtualHost issues in Apache. cPanel support does not directly support customizations to the Apache configuration.
To do this, perform the following actions:
- Log in to WHM as
root - Navigate to Home / Service Configuration / Apache Configuration / Include Editor.
- Under Pre VirtualHost Include, select the 2.4.X Apache version.
- Add the VirtualHost for the IP address over the webserver ports in the box that opens.
- Click Update.
- Click Restart Apache.
Examples of VirtualHost include
You can use any Apache directive that works in the VirtualHost context.
If you want the default Webpage to load on the IP address, add this content, replacing the IP in the VirtualHost directive with the desired IP address on your server:
CONFIG_TEXT: <VirtualHost 10.0.1.1:80>
ServerName 10.0.1.1
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 10.0.1.1:443>
ServerName 10.0.1.1
DocumentRoot /var/www/html
<IfModule suphp_module>
suPHP_UserGroup nobody nobody
</IfModule>
<Directory "/var/www/html">
AllowOverride All
</Directory>
<IfModule ssl_module>
SSLEngine on
SSLCertificateFile /var/cpanel/ssl/cpanel/cpanel.pem
SSLCertificateKeyFile /var/cpanel/ssl/cpanel/cpanel.pem
SSLCertificateChainFile /var/cpanel/ssl/cpanel/cpanel.pem
SSLUseStapling Off
</IfModule>
<IfModule security2_module>
SecRuleEngine On
</IfModule>
</VirtualHost>
Do this for each IP on the server if desired.
Comments
0 comments
Article is closed for comments.