Redirect IP to domain help

(post deleted by author)

After the thing is turned off, what do you want displayed when the IP address is entered in Google Chrome?

The IP. So if I put for example it shows my website and the IP in chrome

And you don’t expect it to show a website? That’s not a redirect. That’s Apache doing what it’s always done. The first best matching virtual host (according to Apache’s somewhat opaque logic) is what it will serve for the bare IP.

In Virtualmin, you could create a new virtual server and make it the default virtual server: then the content that you put in public_html of that virtual server will show in Google Chrome when your IP address is entered in the address bar / omnibox.

So, enter in Chrome and see content of new virtual server - not your existing virtual server / website.

Note that the content of your existing virtual server will be visible only when the domain name(s) associated with the existing virtual server is entered in the address bar / omnibox, which I suppose is what you want.

I have no idea. It doesn’t make any sense to care about this. Virtualmin isn’t explicitly configuring a redirect here, and as far as I know, it isn’t an explicit redirect. It is Apache doing what it normally does in a name-based VirtualHost configuration.

I can’t imagine a situation where you would need to use the IP of the server, and, Apache will show one of your websites when you hit the IP. So, set the default website to be the one you want, if it isn’t already, and move on. You’re obsessing over something that doesn’t make sense. You don’t need to use IP addresses. We live in the future where names can be automatically mapped to IPs via DNS and the web server can determine what site you want based on the hostname in the request header.

Maybe it’s possible to create a VirtaulHost where the ServerName is the IP address but that seems dark and terrible. I think you should stop all this before you go mad.

Also, I don’t think you ever configured a redirect as you think you did. There isn’t anywhere in Virtualmin or Webmin where you can configure “redirect IP to domain” (at least not without writing the redirect rule explicitly), because that’s not a thing people do. There definitely isn’t a button for it (there is a way to set the “default” site, but that’s not a redirect, that’s making the default site the first in the list Apache sees, so that it chooses it when nothing else is a better match because Apache chooses the best-first match for a request).

Ah. You’re asking the wrong question, entirely. In the future start with the problem you’re trying to solve, not what you think the solution is.

You have a couple of choices here:

  1. Install Cacti into a Virtualmin managed VirtualHost (in /home/domainname)
  2. Create a VirtualHost that points to where Cacti lives.

Your Apache is in VirtualHost mode. It no longer serves the non-VirtualHost DocumentRoot. Once you add a single VirtualHost, the DocumentRoot (usually pointed to /var/www) stops working and cannot be made to work again without making a VirtualHost for it. This is not a Virtualmin thing. This is how Apache works.

You cannot do that without removing all VirtualHosts.

I’ve told you how to solve the problem. Apache is now in virtual hosting mode. The only way to make it not be in virtual hosting mode is to delete all virtual hosts (and never add them again, as long as you want to keep using the IP).

You reckon it’s me that misunderstands?

Yes, can I send you my vps ip in private?

No. I’ve told you how to fix it.

You’re getting help for a free product, right?

Also, as soon as you add a site in Virtualmin that site will be served when entering the IP.
The same applies for nginx btw, the first site to match will be served when hitting the IP.
You want to change the default behaviour of Apache? I suggest you ask them instead.

lol, c’mon, I’ve gone to great lengths to help you. I can’t make Apache behave the way you believe it should. The answer to your problem is a few comments up. Literally, take two minutes to do what I told you to do (either option is fine), and solve the problem.

Or, keep complaining because I won’t…I don’t even know what you expect me to do here. Do you want me to modify Apache to work the way you think it should work? What? What could I possibly do other than tell you how to solve your problem?

I’ve explained what Apache is doing and why it is doing it. I’m not going to argue with you about Apache behavior that you have already observed with your own eyes.

“Default” means no VirtualHosts configured, which will serve the DocumentRoot in the global section of the config file. Once you add a VirtualHost, the global DocumentRoot is no longer there and Apache will always serve a VirtualHost! You cannot have both a global DocumentRoot and VirtualHost sections. It isn’t me or Virtualmin preventing this from working. This is how Apache works. I can’t change that.

You can follow my advice and fix it, or keep stubbornly insisting that things don’t work the way they actually work and that you have observed yourself.

OK, so…I actually tested this on Ubuntu 20.04, and it’s not how I thought it was configured out of the box. The “default” site actually already uses VirtualHosts…and so, should keep working after adding VirtualHosts with Virtualmin (but only for the IP). Who knew? (On CentOS the “default” is a DocumentRoot in the global section.)

Mea culpa. You’re right. This should still work. I don’t know why it’s serving the virtual host instead of what’s in 000-default.

So, post your config files. I can’t even guess what’s going on, since on Ubuntu the default site is already a VirtualHost and my assumptions all along were wrong.

BTW, though, the solutions I gave above would still work. Making a specific VirtualHost rather than the nameless fall-through is best practice, anyway.

Okay thanks, where is the virtualmin/webmin config file?

No, I mean the Apache config files. Specifically the VirtualHost configured in /etc/sites-enabled/domain.conf for the site that is being served when you expect the “default” site.

I don’t see anything that would make it take over.

Are you connecting via https? If so, that explains it (this one has an SSL site while the 000-default.conf does not have an SSL config).

Do you have /etc/apache2/sites-enabled/000-default.conf? What’s in it?

Nop i dont have that file. Im connecting via http and https. Also im pretty sure it was a webmin/virtualmin option that i enabled.