Operating System & Version
CentOS 7.9
cPanel & WHM Version
v96.0.14

jthmgm

Registered
Aug 5, 2021
3
0
1
Yuma, AZ
cPanel Access Level
Root Administrator
I've run into odd situation and feel like I'm close to a solution but can't quite get it to work.

I have a client who's site I'm building on one of our cpanel servers and they have a number of temperature monitors that need to send data to the site every couple of minutes. However their temp monitors are quite old and don't support DNS so they can't use their domain name and have to make an IP based request. (they also can't do SSL and of course while the client does plan on replacing them at some point that's not going to happen anytime soon.)

(in all examples I'm using domain.com in place of the reail domain and 127.0.01 in place of the real IP)

So - basically we have an endpoint like: http://domain.com/util/gettemp.php which is called with a query string containing the data. But the devices that need to reach that endpoint can only do so with the IP and not the domain like: http://127.0.0.1/util/gettemp.php with the query string.

I initially thought mod_userdir would take care of this. But...their devices also don't allow ~'s in urls', so simply loading it as http://127.0.0.1/~client/util/gettemp.php won't work.

I tried adding a redirect with the includes editor like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^util/gettemp.php" "http://www.domain.com/util/gettemp.php" [QSA,L]
</IfModule>

But whether I put it in pre-Main, or pre-virtualHost, or post-virtualHost it doesn't work.

I also tried adding a virtual host config around it and putting it in pre-Main:

<VirtualHost 127.0.01:80>
ServerAlias 127.0.01
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^util/gettemp.php" "http://www.domain.com/util/gettemp.php" [QSA,L]
</IfModule>
</VirtualHost>

Which...broke the default cpanel 404 page...but didn't give the rewrite I was hoping for either.

Note - I can't just do a 301/302 redirect...the devices in question just ignore them, I need to actually remap the URL for apache.

Am I just making an error in my rewrite rule and how I'm adding it - or is there another solution for this anyone can offer?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,295
2,438
363
cPanel Access Level
Root Administrator
Hey there! I can't think of a good solution that wouldn't cause some kind of issue for other accounts on the machine.

Would there be a way to give that user a dedicated IP address? That way the content would be routed to the correct Apache vhost. With the current configuration, no matter how you do it, Apache isn't going to handle that type of IP rewrite, and just going to the main shared IP of the server will lead to the default page. You could change the default vhost to be this specific domain, but you may not want to make that type of adjustment for one client.
 

jthmgm

Registered
Aug 5, 2021
3
0
1
Yuma, AZ
cPanel Access Level
Root Administrator
I might be able to get a dedicated IP for them. Though as you no doubt know with the IPv4 address space pretty much exhausted it's now much more difficult to get extra addresses assigned by most datacenters. Ours doesn't even quote a price for them currently and just says to contact support (which I'm doing now.) I was just hoping since it's a single known URL that it would be possible to capture it with a rewrite and avoid the hassles of getting an extra IP assigned.
 

jthmgm

Registered
Aug 5, 2021
3
0
1
Yuma, AZ
cPanel Access Level
Root Administrator
Good news, the datacenter agreed that this is a legitimate need for an additional IP and assigned one. So I have the site running on it's own IP now and it looks like the situation is resolved.

5 years ago I would have gone with a dedicated IP without thinking about it...but since they've gotten harder to get I hadn't even thought of it as an option.