Problem to configure static website with Apache

Problem Description
I’m trying to set up a static website on my Freedombox not by going the user-based way, but by leveraging a custom Apache config file with a domain name (let’s call it custom.com) that’s not the one used for Plinth (let’s call it main.com)

I also got a SSL certificate via Let’s Encrypt, so I’m all good here.

Details
Here’s my config at /etc/apache2/sites-available/01-custom.com (I used 01 as a prefix to prioritize it over the freedombox config files).

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName custom.com
        ServerAlias www.custom.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/custom
        DirectoryIndex index.html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/custom.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/custom.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Then:

  • I place index.html in /var/www/html/custom.
  • I create the symlink in /etc/apache2/sites-enabled and reload Apache.

Expected Results

I should see the content of that index.html at https://custom.com.

Actual results

When trying to reach my website at https://custom.com, I get redirected to https://custom.com/plinth - even though this is not the domain name I use for that effect - and my Freedombox home page shows up.

What’s the Apache directive I need to add so that https://custom.com shows the content of /var/www/html/custom/index.html?

Interestingly, when going to https://custom.com/category, it shows correctly the content of /var/www/html/custom/category/index.html.

Alternatively…

If I choose to go the user-based way, is it possible to have https://custom.com to show the content of https://main.com/~myuser? I tried to play with a CNAME DNS record, but without success.

1 Like

Hi @etienne

Previously, I totally misunderstood your question. Apologies; I removed my (misunderstood) answer.

Here’s how I tweaked your configuration to get it working:

  • Achieve the certificate (you already have)
  • If need be, create a new folder for your domains website as described here.
  • Remove the <IfModule> arguments along with Include /etc/letsencrytp/options-ssl-apache.conf to revise your conf file as needed in regard to below
<VirtualHost *:443>
    ServerName custom.com
    ServerAlias www.custom.com
    ServerAdmin webmaster@custom.com
    DocumentRoot /var/www/custom.com/public_html

    <Directory /var/www/custom.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/custom.com-error.log
    CustomLog ${APACHE_LOG_DIR}/custom.com-access.log combined

SSLCertificateFile /etc/letsencrypt/live/custom.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/custom.com/privkey.pem

</VirtualHost>
  • Generate symbolic link with a2ensite
  • Restart your apache server with sudo systemctl reload apache2

I got this successfully working. Fingers crossed for now.

Take care.

Thank you very much @Ged296123 for your help and for being thorough as well.
I got the static website working, thanks to you! Your previous answer was also correct.

The thing that I can’t seem to go away is this redirection: when I go to custom.com, it redirects to https://custom.com/index.html. I’ve been searching how to get rid off this index.html bit that pops up automatically in the URL bar, but no success. I think it’s not a big deal anyway.

Thanks again for your help!

Hi @etienne

This is a little old, but I came across the problem of my site redirected to index.html.
I believe this recent post might help.