Question

Page isn't redirecting properly when second virtual host added

Posted April 7, 2021 45 views
ApacheDNS

I have followed the instructions here https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04 to create another virtual host on apache so that I could host two websites from one droplet. I have created a conf file is /sites-available/ like this:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost

        ServerName diffuse-mode.tk
        ServerAlias www.diffuse-mode.tk

        DocumentRoot /var/www/html2

        <Directory /var/www/html2/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.diffuse-mode.tk [OR]
RewriteCond %{SERVER_NAME} =diffuse-mode.tk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

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

Here is the conf file for the original site:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost

        ServerName petersenglish.nyc
        ServerAlias www.petersenglish.nyc

        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

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

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

These conf files were modified by letsencrypt. The other website, which was on there already before I tried to set up this one, already had a letsencrypt SSL certificate. I added one to the new site as well. Right now it is just a simple index.html file in html2. The original website is wordpress.

The problem is that when I go to diffuse-mode.tk, I get the following error from the browser:

**The page isn’t redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.**

At first, before I put in an A record for www, it would go to www.diffuse-mode.tk and say the site is not found.

How can I get diffuse-mode.tk to go to html2?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @pedro71,

There are a couple of things I believe you’ve done but nevertheless, please do try them again:

sudo a2ensite diffuse-mode.tk.conf

If the name of the configuration file is different make sure to change it in your command.

The second is to restart apache like so

sudo systemctl restart apache2

Now, if you are still experiencing the issue, make sure to check your website’s DNS. See if it’s pinging from the correct IP address.

If this doesn’t work out, try removing the following block from the website’s configuration file :

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.diffuse-mode.tk [OR]
RewriteCond %{SERVER_NAME} =diffuse-mode.tk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

I believe this might be causing the issues. Don’t forget to restart apache after you make the changes.

Regards,
KFSys