- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
目前我正在为未登录用户使用 fastcgi_cache 进行缓存,并使用 (if + fastcgi_no_cache + fastcgi_cache_bypass ) 将登录用户直接传递到后端,即 PHP-FPM。
这已经足够好了,但是当 PHP-FPM 开始达到 500+ req/s 时,加载速度开始变慢。
所以我想的是为登录用户创建一个缓存,每个用户都有自己的缓存文件,这可能吗?如果是的话,请给我一些提示。我已经看了很多,但没有任何帮助。
使用 mysql 和 memcached 和 apc 运行自定义 php cms 的站点
cat/etc/nginx/nginx.comf
user username username;
worker_processes 8;
worker_rlimit_nofile 20480;
pid /var/run/nginx.pid;
events {
worker_connections 10240;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off;
error_log /var/log/nginx/error.log warn;
log_not_found off;
log_subrequest off;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 3;
keepalive_requests 50;
send_timeout 120;
connection_pool_size 256;
chunked_transfer_encoding on;
ignore_invalid_headers on;
client_header_timeout 60;
large_client_header_buffers 4 128k;
client_body_in_file_only off;
client_body_buffer_size 512K;
client_max_body_size 4M;
client_body_timeout 60;
request_pool_size 32k;
reset_timedout_connection on;
server_name_in_redirect off;
server_names_hash_max_size 4096;
server_names_hash_bucket_size 256;
underscores_in_headers off;
variables_hash_max_size 4096;
variables_hash_bucket_size 256;
gzip on;
gzip_buffers 4 32k;
gzip_comp_level 1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 0;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/javascript text/xml application/xml application/xml+rss application/atom+xml;
open_file_cache max=3000 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 20s;
open_file_cache_errors off;
fastcgi_buffer_size 8k;
fastcgi_buffers 512 8k;
fastcgi_busy_buffers_size 16k;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_min_uses 1;
fastcgi_cache_path /dev/shm/nginx levels=1:2 keys_zone=website:2000m inactive=1d max_size=2000m;
fastcgi_connect_timeout 60;
fastcgi_intercept_errors on;
fastcgi_pass_request_body on;
fastcgi_pass_request_headers on;
fastcgi_read_timeout 120;
fastcgi_send_timeout 120;
proxy_temp_file_write_size 16k;
fastcgi_max_temp_file_size 1024m;
include /etc/nginx/vhosts/*.conf;
}
虚拟主机设置:
server {
listen 80;
server_name domain.com;
access_log off;
error_log /var/log/nginx/error.log warn;
root /home/username/public_html;
location ~ \.php$ {
# pass cache if logged in
set $nocache "";
if ($http_cookie ~ (MyCookieUser*|MyCookiePass*)) {
set $nocache "Y";
}
fastcgi_no_cache $nocache;
fastcgi_cache_bypass $nocache;
fastcgi_cache website;
fastcgi_cache_key $host$uri$is_args$args;
fastcgi_cache_valid 200 301 302 304 40s;
fastcgi_cache_valid any 5s;
fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503 http_404;
fastcgi_ignore_headers Set-Cookie;
fastcgi_hide_header Set-Cookie;
fastcgi_ignore_headers Cache-Control;
fastcgi_hide_header Cache-Control;
fastcgi_ignore_headers Expires;
fastcgi_hide_header Expires;
fastcgi_no_cache $nocache;
fastcgi_cache_bypass $nocache;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8081;
fastcgi_param SCRIPT_FILENAME /home/username/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|ppt|txt|mid|swf|midi|wav|bmp|js)$ {
root /home/username/public_html;
expires max;
add_header Cache-Control cache;
}
}
php-fpm 配置
emergency_restart_threshold = 10
emergency_restart_interval = 60s
process_control_timeout =10s
rlimit_files = 102400
events.mechanism = epoll
[www]
user = username
group = username
listen = 127.0.0.1:8081
listen.backlog = 10000
pm = dynamic
pm.max_children = 2048
pm.start_servers = 64
pm.min_spare_servers = 20
pm.max_spare_servers = 128
pm.process_idle_timeout = 10s;
pm.max_requests = 50000
request_slowlog_timeout = 40s
request_terminate_timeout = 60s
此外,是否需要更改 php cms 运行自己的 cookie 的方式。?
服务器内存:32GB DDR3 处理器:双 E5620 Centos6 64 位
最佳答案
只是一个建议(以及我目前正在做的)...
为什么不对 nginx 从其上游 cgi 服务器 (php-fpm) 获取的每个唯一 cookie 使用不同的缓存,当在您站点的“登录”部分时 - 这或多或少意味着每个登录用户将获取他们自己的缓存 - 这不是最佳选择,但会有所帮助。
如果您想开始使用带有 cookies/动态内容等的真正奇特的缓存选项,您可能需要在 nginx 前面使用 varnish-cache。
我还有某些位置会在访问时清除任何缓存数据(针对该 URI),例如/admin 或/system 等——我最不想要的是 nginx 提供我的管理后端的缓存副本及其所有在 php-fpm 离线时向黑客提供敏感信息。
关于cookies - fastcgi 缓存如何为登录用户缓存并为每个用户自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12499229/
我正在尝试为我的用户提供使用 Google 或 Facebook 登录的选项。到目前为止,我找到了一个实现 Google 登录流程的示例,但如果我可以在同一 Activity 中实现类似的 Faceb
我有一个网页,它对用户是否登录很敏感。我使用的是 Google 登录 Javascript SDK。当用户到达此页面时,我想显示一个插页式广告(“正在加载...”),然后 1)如果用户已登录则呈现页面
我用 digitalocean 创建了一个 droplet,并使用 apt install mariadb-server 命令安装了 mariadb。现在我想使用 php 连接到我的服务器,我使用这个
这个问题在这里已经有了答案: Inno Setup - Signing fails with "Sign Tool failed with exit code 0x1" (2 个回答) 3年前关闭。
我正在尝试使用他们的新 API 实现 google 登录:https://developers.google.com/identity/sign-in/web/ 登录和注销工作正常。我的问题是我不知道
我的应用程序具有谷歌登录、Facebook 登录和 braintree 集成。 我已将以下代码放入 appdelegate.swift 中: func application(_ applicatio
我有一个 Flask 应用程序,最近在我的登录/退出表单中实现了 Flask-Login: @account.route('/sign-in', methods=['POST', 'GET']) de
friend 们,我是初学者级别的 ios swift 学习者。我一直在尝试在我的试用应用程序中进行谷歌登录。根据来自谷歌开发人员和其他教程的资源,我成功地使用 UIView 进行了登录。然后我试图在
我正在使用 Ionic 在 Codeigniter/Ion_Auth/codeigniter-restclient 之上构建登录系统,当我尝试从“ionic 服务器”登录时,登录可以正常工作,但对 L
在 Docker 文件中我有这个 FROM ubuntu RUN apt update && apt -y upgrade RUN apt install -y sudo # Setup ops us
对于 Java 开发,我使用 Slf4j 和 Logback。 Logger logger = LoggerFactory.getLogger(HelloWorld.class); logger.de
在 Scala 应用程序中进行日志记录的好方法是什么?与语言哲学一致的东西,不会使代码困惑,并且维护成本低且不引人注目。以下是基本要求列表: 简单 不会使代码困惑。 Scala 以其简洁而著称。我不希
我正在尝试将我的登录名转换为 Retrofit2 我的旧 LoginActivity: public class LoginActivity extends Activity { private st
我正在尝试让 google+ 登录在 android 上运行。我的问题是,每当我使用 eclipse 运行它时,google 开发站点上提供的示例都能完美运行。当我签署 apk 并在我的设备上手动安装
这个问题已经有答案了: JS Simple but Safe Login? [closed] (1 个回答) 已关闭 6 年前。 我正在尝试使用 JavaScript 创建登录页面。它实际上只是一个带
其他章节请看: react 高效高质量搭建后台系统 系列 登录 本篇将完成 登录模块 。效果和 spug 相同: 需求 如下:
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 1 年前。
我在使用 ReactJs 中的 facebook-login 组件时遇到问题,代码与文档中的完全一样,但仍然无法正常工作。你能帮我找出我做错了什么吗? import React, { Componen
我有一个项目,其中包含许多具有自己的日志记录的“工具”类。这些日志文件是在应用程序启动时创建的,但在使用之前一直为空。 是否可以告诉logback在启动时不应该创建空文件?但是仅在使用它们时? 不知何
我正在创建一个需要用户授权才能访问某些功能的网站。我目前正在研究用户如何创建帐户以及如何利用 session 来授权他们的登录。用户信息存储在名为 user 的 MySQL 表中,其中可能包括用户名和
我是一名优秀的程序员,十分优秀!