Score:0

Ubuntu Apache2 not sorting sites-enabled correctly

nl flag

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
Nikita Kipriyanov avatar
za flag
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.
nl flag
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.
Score:1
nl flag

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.

Nikita Kipriyanov avatar
za flag
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.
nl flag
I do plan to accept my answer as soon as the system allows me to. Nine hours to go.
Score:-1
de flag

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
Nikita Kipriyanov avatar
za flag
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.
nl flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.