nkcmr
nkcmr

Reputation: 11020

why is $_SERVER['REMOTE_ADDR'] returning 127.0.0.1

I am editing a remote server, and for some reason it is returning 127.0.0.1, I tried it on my iPhone too and it did the same thing.

echo $_SERVER['REMOTE_ADDR']; // returns 127.0.0.1

Upvotes: 2

Views: 6817

Answers (3)

FMaz008
FMaz008

Reputation: 11295

It mean that the client who executed the script is hosted at the location of localhost.

This could be because the script that contain $_SERVER['REMOTE_ADDR'] is called with a CURL request from another script on the same server.

It could also be because of a proxy system.

Possible indirect duplicate of Using Django, why would REMOTE_ADDR return 127.0.0.1 on a web server?

Upvotes: 6

klaaz
klaaz

Reputation: 551

Bit late but I had the same problem on a Plesk 11 server. I found out on a dutch forum (tweakers.net) that it has to do with Nginx which is standard enabled in Plesk 11. Nginx acts as a proxy and provides apache with the data to serve. Because Nginx is delivering the data apache gets the localhost IP from Nginx.

The process for disabling Nginx in Plesk 11 and newer versions is quite simple. Please follow the step-by-step directions and you’ll quickly have Nginx disabled within your Plesk installation.

  1. Login to your Plesk control panel as the administrator Next go to "Tools & Services" and then onto "Services Management"
  2. Under "Services Management" locate "Reverse Proxy Server (nginx)"
  3. Once located, simply stop the "Reverse Proxy Server (nginx)" service.

Once the "Reverse Proxy Server (nginx)" is stopped, you’ll notice that Apache takes over all the web requests.

Upvotes: 1

Brad
Brad

Reputation: 163538

Sounds to me like you are hitting a proxy on that server.

I haven't experimented, but perhaps installations such as nginx will have the same behavior.

Upvotes: 1

Related Questions