hellopasswdphp
[root@localhost vhost]# vi ../nginx.conf /fog_format 修改 17 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' 爲 17 log_format user '$remote_addr $http_x_forwarded_for [$time_local]'
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; 其中combined_realip 日誌名 $remote addr 客戶端IP(公網IP) $http_x_forwarded_for 代理服務器的IP $time_local 服務器本地時間 $host f訪問主機名(域名) $request_uri 訪問的url地址 $status 狀態碼 $http_referer referer $http_user_agent user_agenthtml
添加access_log /tmp/test.com.log user;nginx
[root@localhost vhost]# vi test.com.conf 添加 12 access_log /tmp/test.com.log user; 爲 1 server 2 { 3 listen 80; 4 server_name test.com test2.com test3.com; 5 index index.html index.htm index.php; 6 root /data/wwwroot/test.com; 7 8 if ( $host != 'test.com' ) { 9 rewrite ^/(.*)$ http://test.com/$1 permanent; 10 } 11 12 access_log /tmp/test.com.log user; 13 } [root@localhost vhost]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost vhost]# curl -x 127.0.0.1:80 test2.com/admin/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.4.7 Date: Thu, 04 Jan 2018 08:07:12 GMT Content-Type: text/html Content-Length: 184 Connection: keep-alive Location: http://test.com/admin/index.html [root@localhost vhost]# curl -x 127.0.0.1:80 test1.com/admin/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.4.7 Date: Thu, 04 Jan 2018 08:07:16 GMT Content-Type: text/html Content-Length: 184 Connection: keep-alive Location: http://test.com/admin/index.html [root@localhost vhost]# cat /tmp/test.com.log 127.0.0.1 - - [04/Jan/2018:16:07:12 +0800] "HEAD HTTP://test2.com/admin/index.html HTTP/1.1" 301 0 "-" "curl/7.29.0" 127.0.0.1 - - [04/Jan/2018:16:07:16 +0800] "HEAD HTTP://test1.com/admin/index.html HTTP/1.1" 301 0 "-" "curl/7.29.0"
修改於 180105服務器