0

I have an apache2 config on Ubuntu. Everything was working well until I tried to move all my canonical redirect virtualhosts into a single file instead of having them scattered across lots of other config files.

I arranged my config filenames so that I could strictly control which site was loaded first, and therefore control which of them was Apache's default site. This is the first two files in /etc/apache2/sites-enabled, sorted lexically as ls does by default:

elyograg@smeagol:/etc/apache2$ sudo ls -al sites-enabled total 12 drwxr-xr-x 2 root root 4096 Oct 6 16:13 . drwxr-xr-x 9 root root 4096 Oct 6 16:12 .. lrwxrwxrwx 1 root root 51 Jul 22 2017 000000-unknown.REDACTED.org.conf -> ../sites-available/000000-unknown.REDACTED.org.conf lrwxrwxrwx 1 root root 47 Oct 6 16:13 0000-canonical-redirect.conf -> ../sites-available/0000-canonical-redirect.conf 

Today I added the 0000-canonical-redirect.conf file and I want it to be the second site config file that Apache loads. It used to be that it would load the 000000 file as the default site, but since I added the new one, Apache is choosing that file instead of the 000000 one like I expected it to.

I will be downloading and looking at the source code, but I was hoping that maybe people have run into this before and know for sure that it is a bug.

elyograg@smeagol:~$ dpkg -l | grep apache2 ii apache2 2.4.52-1ubuntu4.1 amd64 Apache HTTP Server ii apache2-bin 2.4.52-1ubuntu4.1 amd64 Apache HTTP Server (modules and other binary files) ii apache2-data 2.4.52-1ubuntu4.1 all Apache HTTP Server (common files) ii apache2-utils 2.4.52-1ubuntu4.1 amd64 Apache HTTP Server (utility programs for web servers) ii libapache2-mod-dnssd 0.6-3.2 amd64 Zeroconf support for Apache 2 via avahi ii libapache2-mod-passenger 6.0.10-3build2 amd64 web application server - apache2 integration ii libapache2-mod-wsgi-py3 4.9.0-1ubuntu0.1 amd64 Python 3 WSGI adapter module for Apache 

EDIT: I tried what I hoped would be a more explicit naming, but it still loads the redirect file first.

elyograg@smeagol:/etc/apache2$ ls -al sites-enabled/ total 12 drwxr-xr-x 2 root root 4096 Oct 6 16:41 . drwxr-xr-x 9 root root 4096 Oct 6 16:12 .. lrwxrwxrwx 1 root root 50 Oct 6 16:25 _0000-unknown.REDACTED.org.conf -> ../sites-available/_0000-unknown.REDACTED.org.conf lrwxrwxrwx 1 root root 46 Oct 6 16:41 111-canonical-redirect.conf -> ../sites-available/111-canonical-redirect.conf 
2
  • Try to not use any characters, only numbers or only letters. The docs say it loads "alphabetically", but what's an "alphabetical" order between "-", "_", "1" and "a" could be locale dependent. My system sorts them as -_0a, but it is not immediately apparent and I would not put a finger on it. Commented Oct 7, 2022 at 8:37
  • 1
    It did turn out to be a locale-related issue. With the shell using en UTF8, and apache using C, the ordering that ls showed me was different than what was actually being used. Commented Oct 7, 2022 at 15:43

2 Answers 2

1

In #httpd on IRC, I was guided to the problem. Not surprised it was user error. Apache is running with LANG=C and my shell is running with LANG=en_US.UTF-8 ... and ls was showing me the order I wanted. Apache is sorting the files exactly as LANG=C dictates and my naming scheme wasn't correct for the results I wanted.

2
  • Which is strange, because I remember I tried to test the sort command in C and UTF8 locales and did not spot a difference. However. if this resolved your issue, please accept your own answer for it to be seen by the people who'll hit the same problem in the future and for the question to not to dangle around as unanswered. Commented Oct 8, 2022 at 5:21
  • I do plan to accept my answer as soon as the system allows me to. Nine hours to go. Commented Oct 8, 2022 at 13:18
-1

if you want to add symbolic link you must define full path of the source file.

I see you only use ../sites-available/some-file.conf

Please try to define full location of the source file like this:

ln -s /etc/apache2/sites-available/some-apache.conf /etc/apache2/sites-enabled/some-apache.conf 

Then reload/restart the service:

service apache2 restart or systemctl restart apache2 
2
  • I always used relative symlinks in sites-enabled and never had any problems. This is certainly not required and ../sites-available/some-file.conf is pretty valid. The order of loading doesn't depend on where the symlinks are point to and whether those are symlinks or plain files or even hardlinked files. Just names get sorted, not the contents. Commented Oct 7, 2022 at 8:28
  • The symlinks that are there were all created by the "a2ensite" script that comes with the ubuntu packaging. If absolute paths were required in the symlinks, debian-derived distros would all have broken packages. Commented Oct 7, 2022 at 13:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.