需求:生产环境的服务器要由a/b/c/d 切换到A/B/C/D/E/F/G/H 其中ABC、ab为联通 DEFGH、cd为电信
先将原服务器的请求都打到新服务器上以测试新服务器上业务的稳定性,配置原则为联通打联通,电信打电信,访问日志仍留在原机器,新服务器不加日志
原生产服务器配置如下
location ^~ /danmu/
{
root /xxx/www/;
rewrite ^/danmu/(.*)$ /danmu/index.php?file=$1 break;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass phpsock;
fastcgi_index index.php;
include fastcgi_params;
access_log /xxx/logs/danmu.log main;
}
原服务器修改后配置如下 拿联通机器ab来说(电信类似)
在nginx.conf中添加
upstream danmu_backend{
server A;
server B;
server C;
}
在server.conf中配置修改为
location ^~ /danmu/
{
root /xxx/www/;
rewrite ^/danmu/(.*)$ /danmu/index.php?file=$1 break;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass phpsock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://danmu_backend;
fastcgi_index index.php;
include fastcgi_params;
access_log /letv/logs/danmu.log main;
}
在新服务器上server.conf中配置如下
location ^~ /danmu/
{
root /xxx/www/;
rewrite ^/danmu/(.*)$ /danmu/index.php?file=$1 break;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass phpsock;
fastcgi_index index.php;
include fastcgi_params;
#access_log /xxx/logs/danmu.log main;
access_log off;//不加访问日志
}
问题1:nginx中的
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_real_ip" $request_length $request_time $upstream_response_time ‘;
在原服务器上显示的日志为
客户端IP - - [07/Aug/2015:00:00:02 +0800] "GET /danmu/list?vid=23195473&start=0&amount=1000&tn=0.99273886019364 HTTP/1.1" 200 177516 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.
0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)" "-" 1080 0.094 0.053
新服务器中如果有日志的话,显示为
旧服务器IP - - [07/Aug/2015:00:00:02 +0800] "GET /danmu/list?vid=23195473&start=0&amount=1000&tn=0.99273886019364 HTTP/1.1" 200 177516 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.
0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)" 客户端IP 1080 0.094 0.053
$remote_addr 和 $http_x_real_ip分别代表什么?