Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


Setup Apache2 Virtual Host for Your Domain Running Nextcloud 27

Adding a new apache/httpd virtual host configuration for Nextcloud.

Caution: You may need to first install the Letsencypt certbot tool for generating SSL Letsencrypt and install the letsencrypt directory paths architecture before creating or enabling symlinks to the virtual host SSL configuration file provided below. See: Install the letsencypt certbot tool on Ubuntu Server 22 04

1. Change the working directory to “/etc/apache2/sites-available/” and create new configuration “nextcloud.conf” using vim or nano.

cd /etc/apache2/sites-available/
vim nextcloud.conf

Change the detail domain name and SSL path directory to your own and paste the configuration to the “nextcloud.conf” file.

This sample virtual host file was posted at

<VirtualHost *:80>

    # auto redirect HTTP to HTTPS
    Redirect permanent /

<VirtualHost *:443>
    DocumentRoot /var/www/nextcloud/

    Protocols h2 http/1.1

    # auto redirect www to non-www
    <If "%{HTTP_HOST} == ''">
        Redirect permanent /

    # log files
    ErrorLog /var/log/apache2/
    CustomLog /var/log/apache2/ combined

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/
    SSLCertificateKeyFile /etc/letsencrypt/live/

    # HSTS
    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All

        <IfModule mod_dav.c>
            Dav off

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud

If using vim, press the ESC button to exit vim's INS mode, and enter :w [enter] to save edits, and then enter :q! to exit Vim. If using Nano, Press “Ctrl+x” and type “Y”, then press 'Enter' to save the configuration and exit.

2. Now activate the 'nextcloud.conf' virtual host configuration by executing the following command.

sudo a2ensite nextcloud.conf

3. Now verify the new apache configuration and make sure you have no error, then restart the apache service.

sudo apachectl configtest
sudo systemctl restart apache2
setup_apache2_virtual_host_domain_running_nextcloud_27.txt · Last modified: 2023/06/21 21:57 by wikiadmin