Right so my nginx config is a trimmed down version of Andrew Welch's config as detailed here.
All good. Caching works a dream on all the public pages.
However now when I go to /admin, it loads the content for the homepage, and all URLs become relative to site.com/admin.
I can go to /admin/login, but logging in doesn't actually work - it just redirects me to /admin/login again with no error message.
fastcgi_cache_path /home/forge/{sitename}/cache levels=1:2 keys_zone=stagecache:100m inactive=1d use_temp_path=off max_size=100m;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/before/*;
server {
listen 80;
listen [::]:80;
server_name {server};
root /home/forge/{sitename}/web;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
ssi on;
client_max_body_size 8M;
# Cache everything by default
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
set $no_cache 0;
if ($request_method = POST)
{
set $no_cache 1;
}
if ($request_uri ~* "/(admin/|cpresources/)")
{
set $no_cache 1;
}
# Change // -> / for all URLs, so it works for our php location block, too
merge_slashes off;
rewrite (.*)//+(.*) $1/$2 permanent;
# Access and error logging
access_log off;
error_log /var/log/nginx/{sitename}-error.log error;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/server/*;
# Load configuration files from nginx-partials
include /etc/nginx/nginx-partials/*.conf;
# Root directory location handler
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Craft-specific location handlers to ensure AdminCP requests route through index.php
# If you change your `cpTrigger`, change it here as well
location ^~ /admin {
try_files $uri $uri/ @phpfpm_nocache;
}
location ^~ /index.php/admin {
try_files $uri $uri/ @phpfpm_nocache;
}
location ^~ /cpresources {
try_files $uri $uri/ /index.php?$query_string;
}
# php-fpm configuration
location ~ [^/]\.php(/|$) {
try_files $uri $uri/ /index.php?$query_string;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
# shared php-fpm configuration
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
# FastCGI Cache settings
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache stagecache;
fastcgi_hide_header Set-Cookie;
fastcgi_cache_valid 200 1d;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
}
# php-fpm configuration for non-cached content
location @phpfpm_nocache {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $query_string;
# shared php-fpm configuration
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
# No FastCGI Cache
fastcgi_cache_bypass 1;
fastcgi_no_cache 1;
}
location ~ /\.ht {
deny all;
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/{sitename}/after/*;
by looking at the headers it doesn't seem that /admin is being cached or anything, and I send a test header in the @phpfpm_nocache
block to prove that it's going to the right place, which makes me think it's a problem with the @phpfpm_nocache
block. And that's where I am now.
So... what's going on?
Cheers!