IP Address showing on Google Index Instead of Website

Joined
Dec 21, 2018
Messages
36
Likes
31
Degree
0
For some reason one of my sites has my VPS IP show up in google webmaster and shows up on google search results if I search the right phrases. Anyone have a suggestion on how I can fix this?

I'm thinking 301 redirect may work but not sure how to set that up exactly.
 
For some reason one of my sites has my VPS IP show up in google webmaster and shows up on google search results if I search the right phrases. Anyone have a suggestion on how I can fix this?

Your site is setup as the the "default" in the Apache (or NGINX) directory or website. In the apache case, it's most likely that in your "/apache2/sites-enabled/default" file that's where your site is setup, and therefore the IP address (cause it uses a wildcard "*" instead of the your domain.com) resolves to that instead of a blank page or nothing at all (similar situation in nginx).

What you have to do is copy the "default" file over to "mydomain.com.conf" (within "sites-available" folder). Then make modifications so only your domain shows up in the :80 and :443 server portions of the configuration and not "*:80" and "*:443". Doing those "*" (stars) means a wildcard and that's the situation that's causing your IP address to resolve as your domain name. You want your http server (apache/nginx) to not resolve anything if the domain is not explicit.

Actually another method that might be easier is to simply redirect all "*" wildcard enteries to your mydomain.com (www and non-www versions within SSL (443 port) and non-SSL (80 or 8080 port). But you have to create separate entries for the "mydomain.com" somewhere - don't suggest "default" file - but you can. I prefer creating separate "mydomain.com.conf" files for each site and going from there.

Then enable the mydomain.com.conf within apache ("a2ensite" command - a2dissite disables a site). Enabling the site creates a link from the "sites-available" folder to the "sites-enabled" folder that makes it live.

Afterwards disable the "default" using "a2dissite" command. This will remove the "default" reference from the "sites-enabled" folder and only leave it within the "sites-available" folder. Then reload/restart apache.

It's a similar process for NGINX.

Apache2 enable/disable: https://www.linode.com/community/questions/311/how-do-i-enabledisable-a-website-hosted-with-apache

Nginx enable: https://stackoverflow.com/questions/4891344/how-do-i-add-new-site-server-name-in-nginx

--

Basically your website is being resolved when you go to your VPS's IP address - either block that ability OR redirect it within your Apache/Nginx file and that will fix it. A 301 redirect is "okay", but I recommend to do it within the server level for this particular situation.
 
Thank you @CCarter I got it working with modifying the apache file. Now one other question, do I have to do anything to get the IP out of google? Or will that happen naturally after it sees the redirect?
 
do I have to do anything to get the IP out of google?

There is nothing left to do, the IP Address should get removed naturally, but worse case scenario you can setup 301 redirects for the wildcard version to the main site.
 
Back