It was posted initially here, but the topic was closed and can’t reopen. I have discovered today that the issue started again. So, I have my domain.com and my-domain.com. I was setting a server alias from my-domain.com to my domain.com, and after some troubles it was working. Today I have discovered that has the same initial problem, that instead of pointing to my domain.com it points to the default virtual server. I really didn’t make any modification to virtual servers after initial setup. The logs for the virtual server and alias didn’t show any intervention so not sure what actually triggered them back to initial error.
If I were a betting man, I’d wager your server IP changed and you’re using IP-based VirtualHost identifiers. If you can’t count on your IP to stay the same on this server, you should use *, instead. But, it could be a variety of other stuff.
It’s always something about the way Apache interprets your VirtualHosts is different from the way you’re interpreting them, and since Apache is the web server, you need to accommodate Apache’s weird little quirks.
The server IP didn’t change, but indeed I have set up virtual hosts to use other IP then default. The machine has 4 IPs each with specific designation. Whenever I create a virtual host, I make sure I select the right IP (anyway, all virtual hosts have the same IP). It is defined in the server template, but somehow for the external IP it comes with the default IP selected not with the IP.
Listing virtual hosts from Apache I noticed that for the alias I got only 2 lines instead of 4 like the rest:
The first 4 lines are for the real domanin for which I try to create alias, the next 4 are for a normal domain and the last 2 are the alias. I’m not sure if the domain aliases should have 4 lines or 2.
Anyway, the .conf are empty for the alias.
3) Opening the conf for the principal domain, I have noticed that for ServerAlias directive it listed also webmail and admin for the alias domain but not the www. I have added it to the list, restarted Apache but to no avail. Somehow, somewhere a step is missing.
First, do not mix * with IP-identified VirtualHosts, even when talking about 80 vs 443. That guarantees Apache behaves in a way that makes no sense to normal human people, this is especially true if your server has multiple IP addresses. Pick one, and do that. If you must use multiple IP addresses (why? all services on a modern system support SNI), you need to use IPs for all.
Fixing that will probably resolve your issue.
Also, the webmail and admin ServerAliases are unrelated to this issue. If you have questions about those, make a new topic.
I didn’t create those hosts. My assumption was Virtualmin created them as it creates non-SSl and SSL sites. For each domain I have created redirects from non-ssl to ssl, as I don’t use non-ssl.
Also, IPs are not an issue as they work as intended.
I really not understand how. As I said, those virtual hosts were created by Virtualmin, not by me. While I’m not sure while they were listed like that, opening /etc/apache2/sites-enabled/mydomain.ro.conf looks ok. The only thing that got my attention is that special subdomains/subservers like admin and webmail for alias were listed as ServerAlias of the main domain, while www and alias domain not. But placing three manually didn’t work as I supposed it would.
Also, noticed something. I have deleted the alias, but in Apache vurtualhosts list it is still present. I have deleted manually, recreated the alias, but still the same problem.
You should not mix and match IP and * VirtualHosts. It doesn’t matter if Virtualmin created them, that just means Virtualmin was misconfigured for your environment.
And, as I said, if you want to talk about ServerAliases, make a new topic. It is unrelated to the issue you are having (those are automatically generated by Virtualmin to redirect to Webmin and Usermin, and, as with everything is configurable).
The list posted above, with * 80 was generated by the comand in the tutorial of your first reply
grep -i ‘virtualhost’ /etc/apache2/sites-enabled/*.conf 2>/dev/null || grep -i ‘virtualhost’ /etc/httpd/conf/httpd.conf 2>/dev/null
, but as you can see, both in site-enable and sites-available, the hosts are correctly defined. The hosts conf for alias domain is empty (not sure how it is designed to be).
Since I have defined in the new server template the correct IP address, all servers and subservers are created correct with the right IP, so should be the server alias as it uses the same template.
What you should do is to make sure that each block in all the domains listed in /etc/apache2/sites-available/ has VirtualHost directives with only*:80 or *:443, without any IPs.
I assumed they wanted to be able to use specific IPs for specific VirtualHosts. Either is OK as long as they are right and not mixed (using * and IPs will always do something you don’t expect, because Apache selects what to serve based on unintuitive ways of interpreting the definition…it looks at IP before name, for example, and if an IP matches, it’ll choose that over *, AFAIK).
That’s a different problem, I think, so we’re making progress.
A 301 would generally be coming from configuration, maybe in an .htaccess file in the DocumentRoot but maybe also something from an application running on the domain?
Actually we are back to square 1 as again redirects to first site. It’s the same behavior like the first time, it works for a while (ok, this time only showed 301, but first time was working).
Now all virtual hosts point to the same IP and port, each virtual host has only one entry, like this:
Since I posted the message with 301 error I didn’t touch the server, somehow looks like it is reverting to a previous state itself (which I believe it is practically impossible).