This is an old revision of the document!
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 using the virtual host SSL configuration provided below. https://installconfig.com/doku.php?id=install_letsencypt_certbot_tool_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.
<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 ESQ 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