[SOLVED] nginx - rewrite causing issues with theme previews

Having trouble installing serendipity?
Post Reply
SlidingHorn
Regular
Posts: 18
Joined: Wed Jul 28, 2010 6:14 pm

[SOLVED] nginx - rewrite causing issues with theme previews

Post by SlidingHorn »

I'm attempting to get s9y working with nginx, and I've gotten just about everything to work. The one problem is that my rewrite block in my nginx config is making the theme preview images inaccessible. Here's the config:

Code: Select all

server {
	server_name localhost 127.0.0.1;
		root /var/www/blog/;
		index index.php index.html;

		location ~ ^/(?:[^/?]*?/|serendipity(?:_admin)?\.(?:JS|css)$|admin$) {
			rewrite ^/templates/(.*$) /templates/$1 break;
			rewrite ^/([^?]*)$ /index.php?/$1;
			rewrite ^/([^?]*?)\?(.*)$ /index.php?/$1&$2;
		}

		location ~ (.*?).inc.php {
			deny all;
		}

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
		}

		error_page 404 /404.html;
		location = /404.html {
			root /usr/share/nginx/html/;
		}

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html/;
		}

	listen 80;
	listen [::]:80;
}
When I go to the "Themes" page, any of the images in /templates_c/template_cache cannot be viewed. Attempting to click the "preview" alt text takes me to an "Error 404..." page. In my nginx logs, attempting this returns the following:

Code: Select all

2022/03/09 17:01:11 [error] 6476#6476: *873 open() "/var/www/blog/serendipity.js" failed (2: No such file or directory), client: 192.168.122.1, server: localhost, request: "GET /serendipity.js?v=1646857372 HTTP/1.1", host: "192.168.122.242", referrer: "http://192.168.122.242/templates_c/template_cache/bartleby.jpg"
Commenting out the rewrite block of the config allows the images to load, so the issue appears to be in there somewhere...Is anyone able to determine where I've messed this up?

Edit: I've noticed that if I "install" any of the themes and then switch back to another theme, they will then be visible, and I can view the preview images as expected. Basically, the issue only seems to be affecting themes in /templates_c/. Once they're installed and moved into /templates/, they show up just fine.

Edit 2: FIXED! Basically all that was needed was to duplicate the rewrite line for the templates directory specifically for templates_c. Per a discussion with Onli on gitter, I'll document my process and create a pull request on the documentation github repo within the next couple days.
Post Reply