nginx : fastcgi_cache

On ne touche qu’à la configuration de nginx. La doc : https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html block http Dans le block http on a : fastcgi_cache_path /home/cache levels=1:2 keys_zone=MyCMS:100m max_size=10g inactive=60m use_temp_path=off; fastcgi_cache_key "$scheme$request_method$host$request_uri"; block server Un exemple pour wordpress : server { listen 80; server_name mycms.net; root /var/www/mycms; set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-..php|^/feed/|/tag/./feed/|/.sitemap..(xml|xsl)") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } location ~ \.php$ { fastcgi_cache MyCMS; fastcgi_cache_valid 200 301 302 60m; fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503; fastcgi_cache_min_uses 1; # fastcgi_cache_lock on; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; add_header X-FastCGI-Cache $upstream_cache_status; try_files $uri $uri/ /index.php; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; add_header X-Frame-Options "SAMEORIGIN"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; } location / { index index.php; try_files $uri $uri/ /index.php?$args; } location ~* \.(js|png|jpg|jpeg|gif|ico|css|woff2|svg|ttf|woff)$ { access_log off;expires 365d;log_not_found off; } location ~ /\.well-known/acme-challenge { allow all;} location ~* /(uploads|files)/.*\.php$ { deny all; } location = /favicon.ico { log_not_found off; access_log off; } location ~ /\. { deny all; } location = /robots.txt { allow all; log_not_found off; access_log off; } }

11 septembre 2022 · 1 min

nginx and redis as pastebin

requirement : redis nginx lua snippets nginx access_by_lua_block { local redis = require "resty.redis" local red = redis:new() red:set_timeout(1000) -- 1 sec local ok, err = red:connect("127.0.0.1", 6379,"pool_size=128") if not ok then ngx.exit(503) return end local key = ngx.var.uri local method = ngx.var.request_method if method == "POST" or method == "PUT" then -- local set value = ngx ngx.req.read_body() local data = ngx.req.get_body_data() red:set(key,data) ngx.say("ok") return end if method == "GET" then local res, err = red:get(key) if res ~= ngx.null then -- ngx.redirect(res, 301) ngx.header["Content-type"] = "text/plain; charset=UTF-8" ngx.say(res) return end end if method == "DELETE" then red:del(key) ngx.say("deleted") -- return end } location nginx location / { include /etc/nginx/snippets/api.lua; try_files $uri $uri/ =404; } redis.lua from https://github.com/openresty/lua-resty-redis/releases ...

13 juillet 2022 · 1 min

Redirection de 2 millions d'url avec nginx et redis

On a essayé de rediriger 2 millions d’url avec la fonction remaps de nginx. Les redirections occupaient beaucoup de temps CPU et chargaient la mémoire du serveur (1Go). Les temps de réponses étaient très moyens. Une autre solution est possible sans ces inconvénients. On récupère la lib lua sur OpenResty. https://github.com/openresty/lua-resty-redis On le range et on édite nginx.conf pour placer le chemin ci-dessous dans la balise http : lua_package_path "/etc/nginx/lib/redis.lua;;"; On édite la conf du vhost : ...

18 février 2019 · 1 min