Preserving visitor IP addresses
Peakhour acts as a reverse proxy that sits between your website and end clients. After you have successfully pointed your domain to Peakhour, all visits to your website will only come from Peakhour IP addresses. To preserve the original IP addresses of visitors in your access logs, you need to configure your web server to check the X-Peakhour-IP header. This header contains the IP of the request that is coming into Peakhour.
Why is it Important to Preserve Visitor IP Addresses?#
Preserving visitor IP addresses can be important for a number of reasons, including:
- Fraud detection: IP addresses can help identify fraudulent activity on your website. For example, if a large number of requests from the same IP address are made in a short period of time, this may indicate a potential attack.
- Payment providers: Payment providers may require access to visitor IP addresses to process transactions securely. This information can be used to verify the location of the visitor and prevent fraud.
- Site diagnostics: IP addresses can help diagnose issues with your website, such as slow load times or errors. For example, if a large number of visitors are experiencing issues from a specific geographic location, this information can help identify and resolve the issue.
- User tracking: Preserving visitor IP addresses can provide valuable information about your visitors, such as their location, and can help you better understand your audience and improve the user experience on your website.
- Compliance: Certain regulations, such as the European Union's General Data Protection Regulation (GDPR), may require you to collect and store information about visitors, including their IP addresses.
Preserving visitor IP addresses can provide valuable information for fraud detection, payment processing, site diagnostics, user tracking, and compliance with regulations. By configuring your web server to check the X-Peakhour-IP header, you can preserve the original IP addresses of visitors when using Peakhour as a reverse proxy.
How to set the REMOTE_ADDR variable in a webserver from the X-Peakhour-IP header?#
To set the client's IP address using the X-Peakhour-IP header in Apache, you can use the following configuration in your Apache server configuration file:
LoadModule remoteip_module modules/mod_remoteip.so
<VirtualHost *:80>
ServerName example.com
RemoteIPHeader X-Peakhour-IP
RemoteIPInternalProxy 10.0.0.1
# ...
</VirtualHost>
In Nginx, you can set the client's IP address using the X-Peakhour-IP header with the following configuration in your nginx.conf file:
# set the REMOTE_ADDR variable
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Peakhour-IP;
After adding the configuration, you need to restart your Apache or Nginx server for the changes to take effect.
After these changes, in PHP, you can retrieve the client's IP address using the $_SERVER['REMOTE_ADDR'] variable.
How to log the X-Peakhour-IP header with Apache, Nginx, and IIS to preserve visitor IP addresses.#
Logging the X-Peakhour-IP with Apache:#
- Edit the Apache configuration file (e.g., httpd.conf or apache2.conf).
- Add the following code to the file:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{X-Peakhour-IP}i" combined
CustomLog logs/access_log combined
- Save the changes and restart Apache.
Logging the X-Peakhour-IP with Nginx:#
- Edit the Nginx configuration file (e.g., nginx.conf).
- Add the following code to the file:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_peakhour_ip"';
access_log /var/log/nginx/access.log main;
- Save the changes and restart Nginx.
Logging the X-Peakhour-IP with IIS:#
- Open the IIS Manager and go to the server level.
- Right-click on the server level and select "Server Farms."
- Select the "Logging" option.
- In the "Centralized Logging" section, select the "Add" button.
- Add the following code to the "Custom Field:" section:
c-ip:%{X-Peakhour-IP}i
- Save the changes and restart IIS.
With these configurations, you can preserve the original IP addresses of visitors in your access logs when using Peakhour as a reverse proxy. Please note that the exact steps to configure X-Peakhour-IP header may vary depending on your web server version and setup.