Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


setup_apache2_virtual_host_domain_running_nextcloud_27

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 https://www.howtoforge.com/how-to-install-nextcloud-on-debian-11/

<VirtualHost *:80>
    ServerName files.domain-name.io
    ServerAlias www.files.domain-name.io

    # auto redirect HTTP to HTTPS
    Redirect permanent / https://files.domain-name.io/
</VirtualHost>

<VirtualHost *:443>
    ServerName files.domain-name.io
    ServerAlias www.files.domain-name.io
  
    DocumentRoot /var/www/nextcloud/

    Protocols h2 http/1.1

    # auto redirect www to non-www
    <If "%{HTTP_HOST} == 'www.files.domain-name.io'">
        Redirect permanent / https://files.domain-name.io/
    </If>

    # log files
    ErrorLog /var/log/apache2/files.domain-name.io-error.log
    CustomLog /var/log/apache2/files.domain-name.io-access.log combined

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/files.domain-name.io/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/files.domain-name.io/privkey.pem

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

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

        <IfModule mod_dav.c>
            Dav off
        </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
    </Directory>
</VirtualHost>

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