简要:
server {
listen 80;
server_name www.yunjisuan.com;
location / {
proxy_pass http://www_server_pools;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
#在代理向后端服务器发送的http请求头中加入X-Forwarded-For字段信息,用于后端服务器程序,日志等接收记录真实用户的IP,而不是代理服务器的IP
}
}
}
日志格式设置
log_format main'$remote_addr-$remote_user[$time_local]"$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
log_format main '$remote_addr" "$remote_user" "[$time_local]" "$request"'
' "$status" "$body_bytes_sent" "$http_referer"'
' "$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
' "$upstream_addr" "$request_time" "$upstream_response_time" "$http_host"';
静态缓存
http层
proxy_connect_timeout 10;
proxy_read_timeout 180;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 96k;
proxy_temp_file_write_size 96k;
proxy_temp_path /tmp/temp_dir;
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g;
server层
server {
listen 80 default_server;
server_name localhost;
root /mnt/blog/;
location / {
}
# 静态文件html缓存
location ~ /*\.html$ {
proxy_pass http://127.0.0.1:8000$request_uri;
proxy_redirect off;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1d;
proxy_cache_valid any 5m;
expires 1d;
add_header wall "hey, nginx静态文件缓存";
}
}
————————————————
版权声明:本文为优快云博主「&Faker^」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/qq_44710985/article/details/115458288