cPanel is used on shared hosting when there are many websites using the same server and shared IP address. When you just request the IP address, your host doesn't know which of the many hosted sites you want. That is the reason that your host is returning a 404 error. There are a few ways to get around this.
Use a subdomain for your origin
You can change your origin server to use a different host name. In cPanel, you can accomplish this by changing the primary domain. So your origin server used to be example.com
but in the future it might be origin.example.com
. You would need to add DNS records for this subdomain that point to the same server IP address. Then point the example.com
and www.example.com
records to your proxy server and configure your proxy server to proxy http://origin.example.com
.
It would also be a good idea to put canonical tags in your pages with your preferred host name (example.com
not origin.example.com
) so that if search engines find the non-proxied version, they don't index it.
Configure your proxy to send a Host
header
The requests that specify your origin server by IP address (1.1.1.1
for example) just need to be upgraded with the domain name to use. The configuration for this depends on the proxy software you are using. If you are using Apache with mod_proxy, you can use the RequestHeader
directive.
ProxyPass "/" "http://1.1.1.1/"
ProxyPassReverse "/" "http://1.1.1.1/"
RequestHeader set Host www.example.com
Use your /etc/hosts file
On your proxy server you could override DNS for example.com. You would configure your proxy server to proxy http://www.example.com
and change your /etc/hosts
file to have the IP address of your origin server (1.1.1.1
for example).
1.1.1.1 example.com www.example.com