apache vhost not working consistently
- by petrus
I have a vhost on my webserver whose sole and unique goal is to return the client IP adress:
petrus@bzn:~$ cat /home/vhosts/domain.org/index.php
<?php echo $_SERVER['REMOTE_ADDR']; echo "\n" ?>
This helps me troubleshoot networking issues, especially when NAT is involved. As such, I don't always have domain name resolution and this service needs to work even if queried by its IP address.
I'm using it this way:
petrus@hive:~$ echo "GET /" | nc 88.191.124.41 80
191.51.4.55
petrus@hive:~$ echo "GET /" | nc domain.org 80
191.51.4.55
router#more http://88.191.124.41/index.php
88.191.124.254
However I found that it wasn't working from at least a computer:
petrus@seth:~$ echo "GET /" | nc domain.org 80
petrus@seth:~$
petrus@seth:~$ echo "GET /" | nc 88.191.124.41 80
petrus@seth:~$
What I checked:
This is not related to ipv6:
petrus@seth:~$ echo "GET /" | nc -4 ydct.org 80
petrus@seth:~$
petrus@hive:~$ echo "GET /" | nc ydct.org 80
2a01:e35:ee8c:180:21c:77ff:fe30:9e36
netcat version is the same (except platform, i386 vs x64):
petrus@seth:~$ type nc
nc est haché (/bin/nc)
petrus@seth:~$ file /bin/nc
/bin/nc: symbolic link to `/etc/alternatives/nc'
petrus@seth:~$ ls -l /etc/alternatives/nc
lrwxrwxrwx 1 root root 15 2010-06-26 14:01 /etc/alternatives/nc -> /bin/nc.openbsd
petrus@hive:~$ type nc
nc est haché (/bin/nc)
petrus@hive:~$ file /bin/nc
/bin/nc: symbolic link to `/etc/alternatives/nc'
petrus@hive:~$ ls -l /etc/alternatives/nc
lrwxrwxrwx 1 root root 15 2011-05-26 01:23 /etc/alternatives/nc -> /bin/nc.openbsd
It works when used without the pipe:
petrus@seth:~$ nc domain.org 80
GET /
2a01:e35:ee8c:180:221:85ff:fe96:e485
And the piping works at least with a test service (netcat listening on 1234/tcp and output to stdout)
petrus@bzn:~$ nc -l -p 1234
GET /
petrus@bzn:~$
petrus@seth:~$ echo "GET /" | nc domain.org 1234
petrus@seth:~$
I don't know if this issue is more related to netcat or Apache, but I'd appreciate any pointers to troubleshoot this issue !
The IP addresses have been modified but kept consistent for easy
reading. bzn is the server, hive is a working client and seth is the
client on which I have the issue.