Ce tutoriel abordera un problème où WordPress affiche l’adresse IP de l’hôte local (127.0.0.1) pour l’auteur d’un commentaire au lieu de son adresse IP réelle.
Nous allons d’abord diagnostiquer la cause du problème et ensuite fournir une solution étape par étape pour le corriger. Nous discuterons également de l’importance d’un suivi précis des adresses IP à des fins de sécurité et de modération.
À la fin de ce tutoriel, vous aurez résolu le problème et serez en mesure de suivre avec précision les adresses IP des auteurs de commentaires sur votre site Web WordPress. Il s’agit d’une lecture indispensable pour toute personne rencontrant ce problème et cherchant une solution.
Alors, vous utilisez du Varnish (Caching System)? Cool ! C’est pourquoi vous ne pouvez pas voir l’IP réelle de vos visiteurs. Pas d’inquiétude, voici la solution complète.

Pour résoudre ce problème,
- Connexion à FTP/SFTP
- Allez dans le dossier public_html
- Modifier wp-config.php
- Ajoutez le code ci-dessous juste avant /* That’s all, stop editing! Happy blogging. */
- Sauvegarder les changements.
/** Required Code for showing correct IP address */
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $xffaddrs[0];
}
Mark : Ce petit problème, je l’ai rencontré avec l’hébergement Cloudways.
Cas alternatif
De même, si votre adresse IP est incorrecte après l’utilisation de Cloudflare, voici la solution.
/** Correct IP in case of Cloudflare **/
if(array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)){
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
Alternativement, si vous avez une pile LEMP avec un accès root, alors ajoutez la règle ci-dessous sous Server Block. Vous pouvez trouver votre fichier de configuration dans le répertoire /etc/nginx/sites-available/
.
server {
root /var/www/html;
index index.php index.html index.htm;
server_name .example.com;
# Get real IP
set_real_ip_from 0.0.0.0/0;
set_real_ip_from ::/0;
real_ip_header X-Forwarded-For;
...
Si vous ne vous sentez pas à l’aise pour modifier le fichier wp-config.php, ajoutez l’extrait ci-dessus à l’aide du plugin Code Snippets. Cela fonctionnera parfaitement. J’espère que ce guide vous aidera dans la bonne direction. Merci
Awesome Gulshan. Was having the same issue with the local ip address showing instead of the real ip address.
Glad to know you found it. Thanks
Where should I put it Gulshan. Right after <?php opening or /** which is already been there?
Hi,
Thanks for coming back.
You need to put code just before this line
/* That's all, stop editing! Happy blogging. */
Hi, I’ve found your blog from shoutmeloud forum, and it’s great for optimizing wordpress.
What plugin/code you’re using for the responsive mobile menu at the left corner of the header? I need one badly.
I was looking for the same. It is showing 127.0.0.1. Fixed it. your blog seems very handy for wordpress fixes/optimizations. thanks.
Hi Tirupati,
I am so glad you found my blog. Thank you so much.
Thank you Gulshan. I thought someone is commenting from my server itself. It looks like this problem exists in Cloudways.
You’re welcome! This problem exist in the Cloudways web hosting. Not a big issue though.
nice artical sir, very usefull your post thanks for information provide
Hi Pushpendra, Thank you so much for the kind comment. I am so glad you found it useful.
Hi Gulshan
Nice Post about , error of local host in wordpress keep it up
Thanks. Thats exactly what I was looking for. Also using and loving Cloudways! 🙂
Hi dear, Thanks for the kind comment. I am glad to hear from you. 🙂
I tried both of method mentioned here but still, I got same error plz help me 🙁
That’s the exact problem I was facing. The Cloudways support did rectify it twice but they never shared the solution. It was Mustasaam who referred me to this page.
The solution works perfectly for me. Thank you for sharing.
Just one more query, how did you hide the Website option from the comments box? Most of my readers are internet noobs who feel filling out the Website section is mandatory. I too want to get the same removed. Mind sharing an article on my email ID?
Thanks for visiting.
To hide website field, you can use below snippet.
Time it shows is of the server not the user. Is it possible to check user time as well?