After using the CDN acceleration tool, if we want to view the website logs, we will see that all the recorded IPs are the IP addresses of the CDN nodes, not the user's real user IP records. In this way, if we need to perform log analysis, it is more difficult, Lao Jiang is more commonly used is the Nginx environment, so how can we set up the Nginx environment, while we want to use CDN to accelerate, the website logs can also see the real IP address. First, modify the Nginx.conf file
/usr/local/nginx/conf/ Generally, there is an nginx.conf file in this directory, and we need to add the following script in http: log_format access '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" '; Set the log format, if you don't want to understand what it means, just add it, I tested it without any problem. Second, modify the current site format log
/usr/local/nginx/conf/vhost/ Check the current site's configuration file directory and modify it access_log /www/wwwlogs/itbulu.com_nginx.log access; The red part is what we need to modify/add. Third, restart Nginx service nginx reload If you restart Nginx, if you see Success, it means that there is no problem with the nginx configuration. In summary, many of our friends here may not use the same Nginx environment, but the meaning is probably the same, we can modify it in a targeted manner. In this way, while we use CDN acceleration, we can also see real IP access records in the website logs. The following is the configuration, and the obtained IP is the real IP of the user
Attach your own profile
|