技术解析

nginx 前端加速 proxy_cache, 能否将原网站使用的图床图片缓存,地址改成现在反向代理后网站地址。
0
2021-05-20 20:51:50
idczone
小白用户,反向代理一个网站 aaa.com大带宽服务器 为 bbb.com ,aaa.com 为加密,bbb.com 升级到 https。
aaa.com 内容使用图床贴一下配置
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 128;
multi_accept on;
use epoll;
}
http {
/> Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 64;
server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;

/> Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /etc/nginx/cache/temp;
proxy_cache_path /etc/nginx/cache/path levels=1:2 keys_zone=cache_one:32m inactive=1d max_size=1g;
/> Gzip Settings
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
/> nginx-naxsi config
/> Uncomment it if you installed nginx-naxsi
/etc/nginx/naxsi_core.rules;
/> Virtual Host Configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name bbb.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name bbb.com;
ssl on;
ssl_certificate cert/shss.crt;
ssl_certificate_key cert/shss.key;
ssl_session_timeout 8m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256::!MD5;
ssl_prefer_server_ciphers on;
}
location / {
sub_filter aaa.com bbb.com;
proxy_pass http://aaa.com;
proxy_http_version 1.1;
proxy_redirect off;
proxy_cache_key "$scheme://$host$request_uri";
proxy_cache cache_one;
proxy_cache_valid 200 304 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 10s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://aaa.com;
proxy_set_header Host $proxy_host;
proxy_set_header Accept-Encoding "";
}
}
}

https://www.nginx.com/resources/wiki/modules/substitutions/

subsfilter 模块了解下

subs_filter 批量替换吧




如果源站本身走 HTTPS 协议,怎么破?

图床
这是啥软件

JuiceSSH
反代不用太在意 原站协议...

subs_filter 好像是不支持 HTTPS 协议的啊

这俩没关系.... 倒是反代的时候关 gzip 倒是真的... 不然没法替换

关闭 gzip,问题怎么写代码?谢谢!小白,虽然学过计算机,现已转行。

你需要
1. aaa.com 的反代并且使用 subs_filter 的正则来替换你需要替换的 img 标签
2. 图床的反代
关 gzip 就是 proxy_set_header Accept-Encoding " ";

图床不是固定的,看用户用那个?怎么处理。我想将
数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服