You are not logged in.

#1 Yesterday 17:56:26

CJSHayward
Member
Registered: Yesterday
Posts: 1

Break out Apache VirtualHosts to be friendly to Certbot

I am working on a development site to replace a Debian webserver.

Right now, after installing Apache, VirtualHosts are handled in a single file. I would like to change that to read /etc/apache/sites-enabled/* so that Certbot can see one VirtualHost's information in one file. (Question: Is this the most idiomatic way to do it? If not, what is?)

Right now I have, in /etc/httpd/conf/extra/httpd-vhosts.conf:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/etc/httpd/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/etc/httpd/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>

IncludeOptional /etc/httpd/sites-enabled/*.conf

(I earlier tried an IncludeOptional of sites-enabled/*.conf. If this file is not being consulted because mod_log_config is not enabled, how do I enable this?)

The content of /etc/httpd/sites-enabled/001-dev.orthodoxchurchfathers.com is:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName dev.orthodoxchurchfathers.com
    #ServerAlias orthodoxchurchfathers.cjshayward.com
    #ServerAlias www.orthodoxchurchfathers.com fathers.jonathanscorner.com

    DocumentRoot /var/www/orthodoxchurchfathers.com/document_root
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www>
        Options ExecCGI FollowSymLinks Indexes MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    DirectoryIndex index.cgi index.html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

When I point my browser to http://dev.orthodoxchurchfathers.com, it displays the stub index.html I placed in /srv/http.

What can/should I be doing so that Apache is looking for VirtualHosts in sites-enabled/*.conf?


TIA,

Offline

#2 Today 19:39:53

izracunpostotka
Member
From: Zagreb, Croatia
Registered: Today
Posts: 1
Website

Re: Break out Apache VirtualHosts to be friendly to Certbot

You are very close — the problem is almost certainly the file name, not the IncludeOptional idea. Your IncludeOptional pattern is sites-enabled/*.conf, but the file you created is called 001-dev.orthodoxchurchfathers.com, with no .conf extension. The glob does not match it, so Apache never reads the file, and with no matching vhost it falls back to the main server, which serves /srv/http — exactly the stub page you are seeing. Rename the file to 001-dev.orthodoxchurchfathers.com.conf, restart Apache, and check with apachectl -S that the vhost is listed.

To see what Apache is actually loading, run apachectl -S as root. It lists every vhost and the file it came from, so you will know immediately whether your IncludeOptional is working. Also check that httpd.conf really includes it: grep -n Include /etc/httpd/conf/httpd.conf. The stock /etc/httpd/conf/extra/httpd-vhosts.conf is only an example file — the comment about mod_log_config at the top refers to the example vhosts inside it using CustomLog. On Arch that module is loaded by default, so it is not your problem.

One file per vhost with an IncludeOptional line at the end of httpd.conf is the usual way to do this on Arch, and it is exactly what Certbot wants — the Apache plugin reads one vhost per file and needs a ServerName in each. Keep the stock httpd-vhosts.conf as it is and do not edit it; put your own IncludeOptional line in httpd.conf instead, for example:

IncludeOptional /etc/httpd/sites-enabled/*.conf

Then systemctl restart httpd, and test from the server itself with curl -H "Host: dev.orthodoxchurchfathers.com" http://127.0.0.1/ — if that shows your site, the vhost is working and the only remaining thing is making sure dev.orthodoxchurchfathers.com resolves to this machine. For local testing, add it to /etc/hosts.

One more thing to check while you are there: your Directory blocks use the old Apache 2.2 syntax (Order allow,deny and allow from all). Arch ships Apache 2.4, where that syntax only works if mod_access_compat is loaded — the modern form is Require all granted. And make sure /var/www/orthodoxchurchfathers.com/document_root exists and is readable by the http user. Arch ships /srv/http as the default DocumentRoot, but /var/www works fine as long as the permissions are right — if Apache returns 403 once the vhost starts matching, that is where to look.


Bavim se matematikom u web aplikacijama — točan izračun postotka, PDV i zaokruživanje.
Radim na hrvatskom kalkulatoru postotaka Izračun postotka.
Volim Arch jer je jednostavan, brz i precizan — kao i dobar izračun.

Offline

Board footer

Powered by FluxBB