Forum Moderators: phranque

Message Too Old, No Replies

Any domain that isn't set up to rewrite to a given domain

         

csdude55

9:26 pm on Dec 21, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a way to set up Apache so that any domain that is pointing to my server's IP (via A records) and is NOT set up on the server would automatically rewrite (invisible) to a given domain?

phranque

8:00 am on Dec 23, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



https://httpd.apache.org/docs/2.4/mod/core.html#virtualhost
If multiple virtual hosts contain the best matching IP address and port, the server selects from these virtual hosts the best match based on the requested hostname. If no matching name-based virtual host is found, then the first listed virtual host that matched the IP address will be used. As a consequence, the first listed virtual host for a given IP address and port combination is the default virtual host for that IP and port combination.

the default virtual host configuration is where you need to put the rewrite.

csdude55

6:52 pm on Dec 23, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Looking at /etc/apache2/conf.d/httpd.conf, all of the Virtual Hosts start like this:

<VirtualHost 123.45.67.89:80>
ServerName example.com
ServerAlias foo.com bar.com etc.com

DocumentRoot /home/example/public_html
ServerAdmin webmaster@example.com
UseCanonicalName Off

blah blah blah
</VirtualHost>


It SOUNDS like I could simply remove ServerName and ServerAlias from the one that I want to be the default? And then it would be the first (only) one to match if something isn't defined. Right?

My .conf says in big bold letters,

# !
# DO NOT EDIT. AUTOMATICALLY GENERATED. USE INCLUDE FILES IF YOU NEED TO MAKE A CHANGE
# !
#
# Direct modifications to the Apache configuration file WILL be lost upon subsequent
# regeneration of this configuration file, or an Apache update.
#
# To have your modifications retained, you should create/edit administrator-specific
# include files:
#
# /etc/apache2/conf.d/includes/pre_main_global.conf
# /etc/apache2/conf.d/includes/pre_virtualhost_global.conf
# /etc/apache2/conf.d/includes/post_virtualhost_global.conf


So maybe I should copy the <VirtualHost> minus ServerName and ServerAlias to pre_virtualhost_global.conf?

The only concern THERE is that I have this section:

 <IfModule proxy_fcgi_module>
<FilesMatch \.(phtml|php[0-9]*)$>
SetHandler proxy:unix:/opt/cpanel/ea-php74/root/usr/var/run/php-fpm/blahblahblah.sock|fcgi://example.com
</FilesMatch>
</IfModule>


When I update PHP to the next version, I guess I'd have to remember to manually change this line?

phranque

10:59 am on Dec 24, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



reread my quoted documentation.
additionally:
A ServerName should be specified inside each <VirtualHost> block. If it is absent, the ServerName from the "main" server configuration will be inherited.

i would try to configure another virtual host and specify a wild card hostname for the ServerName directive such as *.com

csdude55

6:54 pm on Dec 27, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the sake of posterity, I found out that this concept doesn't work at all now thanks to SSL. The certificate wouldn't be registered to the proper domain, so the user would get a security warning.

Oh well :-/

lucy24

11:51 pm on Dec 27, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is about your planned low-budget hosting service, isn't it? It might help to think about what real-life situations would lead to someone asking for a previously existing domain that has mysteriously vanished from your server (if it never existed, why would the DNS point to you?), and then consider what response they deserve.