Score:0

Drop all connections from other domain except from original domain on Apache 2.4

cn flag

I have ubuntu server with apache 2.4 web server and original domain is running with ssl. Someone pointed their domain to my server and in my virtual host, it specify there the servername and serveralias so it should accept only connection from original domain, below is the virtual host

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot /var/www/interoptive.com
    ServerName interoptive.com
    ServerAlias interoptive.com

    <Directory /var/www/interoptive.com>
    AllowOverride All
    allow from all
    Options -Indexes
   </Directory>

    ErrorLog /var/www/interoptive.com/apache.error.log
    CustomLog /var/www/interoptive.com/apache.access.log common
    php_flag log_errors on
    php_flag display_errors off
    php_value error_reporting 2147483647
    php_value error_log /var/www/interoptive.com/php.error.log

  Include /etc/letsencrypt/options-ssl-apache.conf
  ServerAlias interoptive.com

  SSLCertificateFile /etc/letsencrypt/live/interoptive.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/interoptive.com/privkey.pem

  RewriteEngine on
  RewriteCond %{SERVER_NAME} =interoptive.com
</VirtualHost>
</IfModule>

The original domain is interoptive.com and the other domain is ecomprime.com. How to configure the apache to accept only connections from the original domain and drop all connections from other domain?

Tried sources from internet but none seems to work. Help, suggestions, recommendations is greatly appreciated. Thanks in advance.

Score:0
jp flag

This is normal per Apache's Virtual Host Matching for Name-based vhost:

If there are multiple VirtualHost directives listing the IP address and port combination that was determined to be the best match, the "list" in the remaining steps refers to the list of vhosts that matched, in the order they were in the configuration file. - -

The first vhost in the config file with the specified IP address has the highest priority and catches any request to an unknown server name - -

Placing a catch-all VirtualHost *:443 before the actual VirtualHost *:443 does what you want. As it is a TLS vhost you also need a certificate, but you can use a certificate you already have since the hostname would not match anyway.

<VirtualHost *:443>
    ServerName catchall
    Redirect 404 /

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/interoptive.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/interoptive.com/privkey.pem
</VirtualHost>

<VirtualHost *:443>
    ServerName interoptive.com
    DocumentRoot /var/www/interoptive.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/interoptive.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/interoptive.com/privkey.pem
</VirtualHost>
Juliver Galleto avatar
cn flag
thank you, you're a life saver
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.