Exception 用于登录的Nginx微缓存异常
我的网站有nginx-php-fpm服务器。我想为nginx使用Microche。一开始一切正常。我用curl命令得到“命中”。当我尝试登录时,问题开始出现。我什么都试过了,但没能解决登录问题 我将“logged_in”cookie设置10秒,并在“cache config”中为该cookie设置“no cache”。它假设在存在cookie时绕过缓存。我没有缓存设置,这是我的登录。 另外,我的网站有example.org/?i=login,所以我现在不知道单击login时发生了什么 主图像是可缓存的,但登录返回未登录主页,刷新后,我成为登录用户。对于注销,它将我注销,但刷新后我仍然登录到用户。所以我不知道如何修复/绕过登录过程 服务器配置:Exception 用于登录的Nginx微缓存异常,exception,nginx,login,Exception,Nginx,Login,我的网站有nginx-php-fpm服务器。我想为nginx使用Microche。一开始一切正常。我用curl命令得到“命中”。当我尝试登录时,问题开始出现。我什么都试过了,但没能解决登录问题 我将“logged_in”cookie设置10秒,并在“cache config”中为该cookie设置“no cache”。它假设在存在cookie时绕过缓存。我没有缓存设置,这是我的登录。 另外,我的网站有example.org/?i=login,所以我现在不知道单击login时发生了什么 主图像是可
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;
}
缓存配置(包括在服务器配置中):
编辑:事实上,经过一些检查,我很确定我的问题只是phpsessid。每个连接都有phpsessid和nginx缓存它们,或者通过指令完全忽略它们。 如果我缓存phpsesid,并且如果首先使用带有管理员帐户的浏览器登录,则每个人都会在缓存中获得管理员登录:D 我需要一个连接phpsessid应该受到保护 就像nginx应该首先清除phpsessid cookie并将php发送给fastcgi一样。从fastcgi服务器nginx返回的php应该附加最初清除的相同phpsessid。 或者像缓存php或者没有phpsessid cookie的任何东西,当从缓存中提供内容时,nginx应该将未触及的官方phpsessid附加到它们 因此,通过这种方式,每个访问者都将拥有唯一的phpsessid和缓存内容,这将解决我的登录问题 我可能可以清除并设置phpsessid。但是我现在不知道如何保存唯一/特定的phpsessid并重新设置它。
或者甚至可能是不可能的。我想出了理论,但不知道怎么做:D非常感谢@哈弗特非常感谢你@半身人
#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;
}