用于login的Nginx Microcache例外

我有我的网站nginx php-fpm服务器。 我想为nginx使用microcache。 起初一切正常。 我用curl命令得到“命中”。 问题开始时,我尝试login。 我尝试了一切,但无法解决login问题。

我设置“logged_in”cookie 10秒,在“cachingconfiguration”我设置“无caching”该cookie。 它假设有cookie的时候绕过caching。 我已经“放”没有caching设置,这是我的login。 另外我的网站有exmple.org/?i=login所以我现在不知道怎么回事,当我点击login:D。

主法师是可以caching的,但是主页面的login返回结果不明了,刷新后我变成了用户。 并注销,它注销我,但刷新后,仍然在用户loged。 所以我不知道如何修复/绕过login过程。

请帮我一下

服务器configuration:

fastcgi_cache_path /usr/share/nginx/cache/fcgi levels=1:2 keys_zone=microcache:32m max_size=1024m inactive=3h; fastcgi_cache_key $scheme$host$request_uri$request_method; fastcgi_cache_use_stale updating error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; add_header X-Cache $upstream_cache_status; server { listen ip:80; server_name example.org; return 301 $scheme://www.example.org$request_uri; } server { server_name www.example.org; listen ip:80; root /home/example/public_html; index index.html index.htm index.php; access_log /var/log/virtualmin/example.org_access_log; error_log /var/log/virtualmin/example.org_error_log; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; include /etc/nginx/example.d/cache.conf; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_cache microcache; fastcgi_cache_key $scheme$host$request_uri$request_method; fastcgi_cache_valid 200 301 302 30s; #fastcgi_pass_header Set-Cookie; #fastcgi_pass_header Cookie; fastcgi_cache_bypass $no_cache; fastcgi_no_cache $no_cache; fastcgi_pass unix:/run/php/php5.6-fpm_example.sock; fastcgi_index index.php; include /etc/nginx/example.d/fastcgi.conf; } location ~* \.(jpg|jpeg|gif|css|png|js|woff|ttf|svg|ico|eot)$ { access_log off; log_not_found off; expires max; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ /\. { access_log off; log_not_found off; deny all; } include /etc/nginx/example.d/redirect.conf; include /etc/nginx/example.d/rewrite.conf; } 

cachingconfiguration(包括在服务器configuration):

 #Cache everything by default set $no_cache 0; #Don't cache POST requests if ($request_method = POST) { set $no_cache 1; } #Don't cache if the URL contains a query string if ($query_string != "") { set $no_cache 1; } #Don't cache the following URLs if ($request_uri ~* "/*login*|/*ajax*|/sistem/modul/login.php") { set $no_cache 1; } #Don't cache if there is a cookie called PHPSESSID if ($http_cookie = "Logged_in") { set $no_cache 1; } 

编辑:其实经过一些检查后,我很确定我的问题只是与phpsessid。 每个连接都有phpsessid和nginxcaching它们,或完全忽略它们的指令。 如果我cachingphpsesid,如果用pipe理员帐户的第一个浏览器login每个人都得到pipe理logincaching:D我需要一个连接phpsessid应该保护。

它像nginx应该首先清除phpsessid cookie并发送到fastcgi的PHP。 并从fastcgi服务器nginx返回该PHP应该附上相同的首先清除的phpsessid。 或者像它的cachingphp或一切都没有phpsessid cookie,并从cachingnginx服务器内容应附加原封不动,官方phpsessid给他们。

所以这样每个访问者将有独特的phpsessid和caching的内容,这将解决我的login问题。

我可以清除并设置phpsessid。 但我现在不怎么保存这个独特/特定的phpsessid并重新设置它。 或者可能是不可能的。 我想出了理论,不知道该怎么做:D

也许你应该采取简单的路线,只需为您的loginURL定义一个块并手动closurescaching。 这是我如何做WordPress的。

我有服务器定义之外的速度限制块(我有一个日志stream量网站,所以每秒1login是绰绰有余)。

 limit_req_zone $binary_remote_addr zone=login:1m rate=1r/s; 

这是在我的服务器

 # Rate limit wp-login.php to prevent brute force attacks location = /wp-login.php { # Next line applies the rate limit defined above limit_req zone=login burst=3; fastcgi_keep_conn on; fastcgi_intercept_errors on; fastcgi_pass php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # No caching more_clear_headers "Cache-Control"; add_header Cache-Control "private, max-age=0, no-cache, no-store"; more_clear_headers "Expires"; } 

这里有更多关于我的Wordpress / Nginx教程。

更新

这是我在我的Nginxconfiguration为WordPress的

 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wordpress_logged_in") { set $skip_cache 1; 

}

阅读我上面链接的教程,我有一个相当有效的Nginxconfiguration的WordPress的,你可以采取原样或复制和粘贴零件。