以下配置文件例子,可以解决大多数代理的问题:
server {
listen 80;
server_name aaaaa.com www.aaaaa.com;
error_page 497 https://$host$request_uri;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443 ssl http2;
server_name aaaaa.com www.aaaaa.com;
access_log /var/log/nginx/aaaaa.log;
error_log /var/log/nginx/aaaaaerror.log;
root /var/www/aaaaa;
index index.html;
ssl_certificate /etc/nginx/key/5938878_aaaaa.com.pem;
ssl_certificate_key /etc/nginx/key/5938878_aaaaa.com.key;
# 去除源站header设置 否则不能缓存到本地
proxy_ignore_headers Set-Cookie Cache-Control;
proxy_ignore_headers Expires;
proxy_ignore_headers X-Accel-Expires;
proxy_hide_header Cache-Control;
proxy_hide_header Set-Cookie;
proxy_hide_header Expires;
# http2 must
proxy_hide_header Upgrade;
location / {
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Referer https://bbbbb.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
subs_filter_types text/css text/xml;
subs_filter bbbbb.com aaaaa.com;
proxy_pass https://bbbbb.com/;
}
}