I've been trying to get a server up and running to deploy my cloud service. Most of my operations are client ip based. When I was using godaddy, the script that returned the client's ip worked fine (php, $_SERVER variable). Now on my server, it's returning 192.168.1.1 (my router/gateway). Why is this? I'm running Apache, PHP5, Ubuntu Server 12.04 LTS. I appreciate it the help in advance.
You're using hairpin NAT, which must rewrite the source IP address. If you're going to connect to an outside IP address from the inside, the source IP address will always have to be the gateway's IP address. Otherwise, the return packets would never get back to the source machine.
My advice to you is simply not to do this. If you want to connect to a local machine, use its local IP address.
This answer explains the same issue.
Here what would happen if you didn't use SNAT:
Hairpin NAT is a form of dual NAT, using both SNAT and DNAT. It cannot work without SNAT. The replies must also be NATted, which means the source has to be NATted to get the replies to the gateway.
Check with tcpdump what the packets look like that reach the server. Maybe SNAT has been activated on the gateway.
This refers to the case that the access is from outside the local net so that SNAT is possible but not necessary.