1.先创建两个静态页面
2.配置nginx.conf,1.com用默认配置,2.com获取X-Forwarded-Host、 X-Forwarded-Proto字段并使用自定义的log格式记录。
server {
listen 8081; # 监听端口为8081
server_name 1.com;
root /var/www/html/;
index 1.html;
# 允许192.168.80.128访问1.com
allow 192.168.80.128;
deny all;
location / {
try_files $uri $uri/ /1.html =404;
# 如果请求不是192.168.80.128,返回403 Forbidden
if ($remote_addr != 192.168.80.128) {
return 403;
}
}
}
server {
listen 8082;
server_name 2.com;
root /var/www/html/;
index 2.html;
# 在location块中使用定义的log_format
location / {
try_files $uri $uri/ /2.html =404;
add_header X-Forwarded-Host $host;
add_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/2.com_access.log combined_extended;
}
}
3.注意在http块中加入
log_format combined_extended '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_x_forwarded_host" "$http_x_forwarded_proto" '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
4.配置雷池
5.修改host
6.访问并查看日志
这是1.com的
这是2.com的,加入了真实ip
1.com可以通过雷池访问而不可以通过ip+端口访问