Last active
January 19, 2024 22:23
-
-
Save janboddez/9220f7e558c3f38c42cd3d535575e98b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream php_fpm { | |
server unix:/run/php/php8.1-fpm.sock; | |
keepalive 10; | |
# Equal to PHP's `pm.max_requests` | |
keepalive_requests 500; | |
} | |
## | |
# Cache setup | |
## | |
fastcgi_cache_path /usr/share/nginx/fastcgi_cache levels=1:2 keys_zone=WORDPRESS:10m max_size=1g inactive=1d; | |
fastcgi_ignore_headers Cache-Control Expires; | |
# To be able to cache ActivityPub responses separately | |
map $http_accept $vary_key { | |
default "default"; | |
"~application/activity\+json" "json"; | |
} | |
## | |
# Server configuration | |
## | |
server { | |
# Update for your specific server (name, ports, SSL termination, etc.)! | |
listen 80; | |
listen [::]:80; | |
server_name example.org; | |
client_body_buffer_size 10K; | |
client_header_buffer_size 1k; | |
client_max_body_size 8m; | |
large_client_header_buffers 2 1k; | |
client_body_timeout 12; | |
client_header_timeout 12; | |
keepalive_timeout 15; | |
send_timeout 10; | |
root /var/www/html; | |
index index.html index.htm index.php; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { | |
expires max; | |
log_not_found off; | |
} | |
# Pass PHP scripts to FastCGI server | |
location ~ \.php$ { | |
# Caching is on by default | |
set $skip_cache 0; | |
# Don't cache the following URLs | |
if ($request_uri ~* "^/wp-") { | |
set $skip_cache 1; | |
} | |
# But do cache GET requests to ActivityPub endpoints | |
if ($request_uri ~* "^/wp-json/activitypub") { | |
set $skip_cache 0; | |
} | |
# Don't cache logged in users or commenters | |
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_") { | |
set $skip_cache 1; | |
} | |
# Don't cache POST requests | |
if ($request_method = POST) { | |
set $skip_cache 1; | |
} | |
# Note the `$vary_key` part | |
fastcgi_cache_key "$vary_key$scheme$request_method$host$request_uri"; | |
fastcgi_cache WORDPRESS; | |
fastcgi_cache_bypass $skip_cache; | |
fastcgi_no_cache $skip_cache; | |
fastcgi_cache_valid any 15s; | |
# Misc. additional settings | |
fastcgi_cache_use_stale error timeout updating http_500; | |
fastcgi_cache_background_update on; | |
fastcgi_cache_lock on; | |
#fastcgi_cache_lock_timeout 10s; | |
fastcgi_cache_lock_age 5s; | |
# All things PHP | |
include snippets/fastcgi-php.conf; | |
fastcgi_intercept_errors on; | |
fastcgi_keep_conn on; | |
fastcgi_pass php_fpm; | |
include fastcgi_params; | |
add_header X-FastCGI-Cache $upstream_cache_status; | |
} | |
} |
Added in the keepalive
bits. Again, :-D not sure if needed, or if it even improves performance (at all).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure if the buffer size and timeout directives really add anything. At one point, I was just trying out about anything I could find.
And even if they do, I might actually move them out to a more generic config file.