LNMP反代Gravatar配置

  • A+
所属分类:工具资源

学习下LNMP下面的Gravatar反代,参考了灵尘居博客文章。运行环境为LNMP1.3,按以下配置时将gravatar.cmsky.com换成自己的域名即可。

准备工作

安装好LNMP1.3,将gravatar.cmsky.com解析记录指向vps,准备好ssl证书。新建虚拟主机,我这里是同时开启了80和443端口。

修改nginx默认配置

vim /usr/local/nginx/conf/nginx.conf,查找#limit_conn_zone $binary_remote_addr zone=perip:10m;,并在前面加入以下内容:

client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/cache/temp;

# 配置临时目录
proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache:20m inactive=30d max_size=600m;
#20m是内存占用,30d是30天无访问删除,600m是缓存占具硬盘空间,cache为缓存区名字.

创建缓存目录,并赋予权限

mkdir /home/cache/path -p
mkdir /home/cache/temp
chmod 755 -R /home/cache

修改虚拟主机配置文件

vim /usr/local/nginx/conf/vhost/gravatar.cmsky.com.conf,以下直接贴出完整配置

server
{
listen 80;
server_name gravatar.cmsky.com;
access_log /home/wwwlogs/gravatar.cmsky.com.log;
location / {
proxy_cache cache;
proxy_cache_valid 200 304 7d;
#200 304状态缓存7天,按实际情况修改
#其他状态缓存(如502 404)10秒
proxy_cache_valid any 10s;
proxy_cache_key "$scheme$host$request_uri";
#缓存key规则,用于自动清除缓存。
proxy_pass https://secure.gravatar.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#向后端传递访客ip
#limit_conn one 20;
#limit_rate 200k;
#20为单ip连接数,200k为单ip连接速度,若要开启请去掉#
}
}
server
{
listen 443;
server_name gravatar.cmsky.com;
ssl on;
ssl_certificate /root/ssl/cmsky.crt;
ssl_certificate_key /root/ssl/cmsky.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
access_log /home/wwwlogs/gravatar.cmsky.com.log;
location / {
proxy_cache cache;
proxy_cache_valid 200 304 7d;
#200 304状态缓存7天,按实际情况修改
#其他状态缓存(如502 404)10秒
proxy_cache_valid any 10s;
proxy_cache_key "$scheme$host$request_uri";
#缓存key规则,用于自动清除缓存。
proxy_pass https://secure.gravatar.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#向后端传递访客ip
#limit_conn one 20;
#limit_rate 200k;
#20为单ip连接数,200k为单ip连接速度,若要开启请去掉#
}
}

编辑完重载nginx,service nginx reload生效。然后在你程序的相应文件出替换就行了,如wordpress是在主题的functions文件。

weinxin
我的微信公众号
我的微信公众号扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: