希望在 nginx 的后端服务中终止 SSL,并以 http 的形式卸载到客户端。缓存所有响应以实现性能和离线场景。使用以下设置我无法缓存,缺少什么?
events {}
http {
include mime.types;
#PROXY
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache_sample:10m max_size=50m;
proxy_cache_key "$scheme$request_method$host$request_uri:w";
add_header cache_sample $upstream_cache_status;
server {
listen 81;
server_name _;
ssl_verify_client off;
location ~* {
proxy_pass https://backend_service;
proxy_set_header Host $http_host;
proxy_set_header X_FORWARDED_PROTO https;
proxy_ssl_certificate /backend_service.crt;
proxy_ssl_certificate_key /backedn_service.key;
proxy_ssl_ciphers HIGH:!aNULL:!MD5;
proxy_ssl_verify off;
}
}
}
答案1
应该可以,请尝试更多类似的东西。我发现有些东西不见了,而且有些东西看起来有点奇怪,比如一行末尾的“:w”。
第一部分超出了你的服务器块
fastcgi_cache_key "$scheme$request_method$host$request_uri";
# Determines in which cases a stale cached response can be used when an error occurs during
# communication with the FastCGI server
fastcgi_cache_use_stale error timeout invalid_header http_500;
# Many websites send back inappropriate headers, so ignore them
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
# Caching. Putting the cache into /dev/shm keeps it in RAM, limited to 10MB, for one day. This is Centos, other distibutions are different.
# You can move to disk if you like, or extend the caching time
fastcgi_cache_path /dev/shm/hr_nginxcache levels=1:2 keys_zone=CACHE_NAME:10m inactive=1440m; #RAM
这位于服务器块顶部附近
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments.
# for everyone. I've removed index.php as I want pages cached.
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|code") {
set $skip_cache 1;
}
这将进入您的位置块
fastcgi_cache CACHE_NAME;
fastcgi_cache_valid 200 1440m;
add_header X-Cache $upstream_cache_status;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
您必须编辑部分内容以适合您的网站。