Ten tutorial zajmie się problemem, w którym WordPress wyświetla adres IP lokalnego hosta (127.0.0.1) dla autora komentarza zamiast jego rzeczywistego adresu IP.
Najpierw zdiagnozujemy przyczynę problemu, a następnie przedstawimy rozwiązanie krok po kroku, aby go naprawić. Omówimy również znaczenie dokładnego śledzenia adresów IP dla celów bezpieczeństwa i moderacji.
Pod koniec tego samouczka rozwiążesz problem i będziesz mógł dokładnie śledzić adresy IP komentatorów w swojej witrynie WordPress. Jest to lektura obowiązkowa dla każdego, kto doświadcza tego problemu i szuka rozwiązania.
Więc, używasz Varnish? Fajnie! To dlatego nie jesteś w stanie zobaczyć prawdziwego IP odwiedzających. Nie martw się, oto kompletne rozwiązanie.

Aby naprawić ten problem,
- Zaloguj się do FTP/SFTP
- Idź do public_html folder
- Edytuj wp-config.php
- Dodaj poniższy kod tuż przed /* To wszystko, przestań edytować! Szczęśliwego blogowania. */
- Zapisz zmiany.
/** Wymagany Kod wskazujący prawidłowy adres IP */
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $xffaddrs[0];
}
Mark: Ten mały problem miałem na Cloudways web hosting.
Alternatywny przypadek
Podobnie, jeśli twoje IP jest wyświetlane nieprawidłowo po użyciu Cloudflare, tutaj jest poprawka -.
/** Przywrócenie poprawnego IP w przypadku Cloudflare **/
if(array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)){
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
Alternatywnie, jeśli masz stos LEMP z dostępem roota, to dodaj poniższą regułę w Server Block. Możesz znaleźć swój plik konfiguracyjny w katalogu /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;
...
W przypadku, gdy nie czujesz się komfortowo w edycji pliku wp-config.php, dodaj powyższy snippet za pomocą wtyczki Code Snippets. To będzie działać dobrze. Mam nadzieję, że ten przewodnik pomoże w dobrym kierunku. Dzięki
Time it shows is of the server not the user. Is it possible to check user time as well?
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.
I tried both of method mentioned here but still, I got same error plz help me 🙁
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. 🙂
Hi Gulshan
Nice Post about , error of local host in wordpress keep it up
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.
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.
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.
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.
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. */
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