1

Hi i have this issue with 3 domains on my server with ububtu 22.04 and apache

I have 3 domains in a shared hosting, each one with their own web page domain-a.com

domain-b.com

domain-c.com

I also have 3 domains in no-ip, which I have redirected to a server in my house that has a dynamic ip (for this reason, the use of no-ip)

in my house I have configured

domain-a.no-ip.com

domain-b.no-ip.com

domain-c.no-ip.com

In each one I have created its own website in apache

/var/www/domain-a (this web use port 8180)

/var/www/domain-b (this web use port 8185)

/var/www/domain-c (this web use port 8190)

I have also created 3 configuration files, one for each domain on /etc/apache2/sites-available

Also i enable the 3 conf files

sudo a2dissite 000-default

sudo a2ensite domain-a.conf

sudo a2ensite domain-b.conf

sudo a2ensite domain-c.conf

sudo service apache2 restart

<VirtualHost *:80>
   ServerName domain-a.no-ip.com
   Redirect / https://domain-a.no-ip.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain-a.no-ip.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
         <VirtualHost _default_:443>

                 ServerName domain-a.no-ip.com
                 ServerAdmin [email protected]

                 DocumentRoot /var/www/domain-a/

                 ProxyPass / http://localhost:8180/
                 ProxyPassReverse / http://localhost:8180/

                 SSLEngine on

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


<VirtualHost *:80>
   ServerName domain-b.no-ip.com
   Redirect / https://domain-b.no-ip.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain-b.no-ip.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
         <VirtualHost _default_:443>

                 ServerName domain-b.no-ip.com
                 ServerAdmin [email protected]

                 DocumentRoot /var/www/domain-b/

                 ProxyPass / http://localhost:8185/
                 ProxyPassReverse / http://localhost:8185/

                 SSLEngine on

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


<VirtualHost *:80>
   ServerName domain-c.no-ip.com
   Redirect / https://domain-c.no-ip.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain-c.no-ip.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
         <VirtualHost _default_:443>

                 ServerName domain-c.no-ip.com
                 ServerAdmin [email protected]

                 DocumentRoot /var/www/domain-c

                 ProxyPass / http://localhost:8190/
                 ProxyPassReverse / http://localhost:8190/

                 SSLEngine on

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

Then in the cloudflare of domain-a i created a CNAME www2 and the target domain-a.no-ip.com

Then in the cloudflare of domain-b i created a CNAME www2 and the target domain-b.no-ip.com

Then in the cloudflare of domain-c i created a CNAME www2 and the target domain-c.no-ip.com

Now if I enter on any web-browser and put www2.domain-a.com or www2.domain-b.com or www2.domain-c.com always redirects me to domain-b on my server at home

But if I enter through the direct addresses domain-a.no-ip.com or domain-b.no-ip.com or domain-c.no-ip.com it sends me to each web page of the server in my house

What surprises me is that if I enter through the no-ip addresses, it redirects me to each of the 3 pages on my server, but if I enter through the 3 cnames, it always redirects me to the domain-b

Thank you

1
  • Note: each post should ask one well defined question/problem and should not present multiple questions or problems. That way you will get better / more focused answered. Your post mixes three different issues: Apache - dynu - DNS. May 3, 2023 at 21:43

1 Answer 1

0

A simple way to resolve this is with ServerAlias in the Apache configuration. Try something like this:

<VirtualHost *:80>
    ServerName domain-c.no-ip.com
    ServerAlias domain-c.com
    Redirect / https://domain-c.no-ip.com/
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =domain-c.no-ip.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName domain-c.no-ip.com
        ServerAlias domain-c.com
        ServerAdmin [email protected]

        DocumentRoot /var/www/domain-c

        ProxyPass / http://localhost:8190/
        ProxyPassReverse / http://localhost:8190/

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domain-c.no-ip.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain-c.no-ip.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
</IfModule>

With ServerAlias, you can also configure multiple domains to point to the same source directory. For example:

ServerAlias domain-c.com *.domain-c.com domain-c.net domain-c.org

Note: Wildcards are supported in the ServerAlias values.

One item to note is that the Let's Encrypt SSL certificate may not work with your CloudFlare domain unless the certificate is valid for multiple domains, or if you are using CloudFlare's SSL externally and forwarding traffic to your home server over HTTP.

1
  • 1
    Thanks i try with server alias and dosent work, im searching info about the SSL from Let's Encrypt. Thanks
    – Leandro
    May 4, 2023 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .