Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement suggestion: for PageSpeed, automatically create cache directory #89

Open
GwynethLlewelyn opened this issue Jun 4, 2019 · 3 comments

Comments

@GwynethLlewelyn
Copy link

Hi there! First of all: awesome script, I found it by mere chance, and it works so flawlessly that it's actually scary...

Now for a suggestion — I've mostly used this script to add pagespeed & brotli support on nginx. pagespeed in particular has a gazillion options, but one that pretty much everyone will be using is, obviously, adding the cache directory.

By convention — and your script follows this convention! — /var/ngx_pagespeed_cache is the default. However, a common configuration change (at least on Ubuntu/Debian) is to use a tmpfs-mounted directory for the cache, say, /run/ngx_pagespeed_cache (and just use a symlink to keep the rest of the default configuration working).

This has a problem: when rebooting, as expected, the content of /run will be lost, and when nginx starts, it expects /run/ngx_pagespeed_cache to exist, and because it doesn't exist any more (just a broken symlink pointing to it), nginx will fail to run.

On systems using systemd, one simple solution is to add a small file under /usr/lib/tmpfiles.d, which will tell the system what to create when starting up. In fact, a lot of packages (mysql, php-fpm, among so many others...) use this method to set up sockets, for example, which are conveniently created on a tmpfs volume for added speed.

It would be nice if a future version of nginx-autoinstall would be able to create something like that automatically, e.g.:

echo "d /run/ngx_pagespeed_cache 0755 www-data www-data - -" > /usr/lib/tmpfiles.d/nginx.conf
ln -s /run/ngx_pagespeed_cache /var/ngx_pagespeed_cache

This could be one of the (many) extra options for those interested in having a tmpfs-based cache for pagespeed...

Keep updating nginx-autoinstall, great job so far, and thanks again!

@GwynethLlewelyn GwynethLlewelyn changed the title Enhancement suggestion: for PageSpeed, automatically create directory Enhancement suggestion: for PageSpeed, automatically create cache directory Jun 4, 2019
@angristan
Copy link
Owner

Interesting suggestion, thanks

@adamaayala
Copy link

adamaayala commented Jun 30, 2019

EDIT: Foot in mouth.
Create a directory. Insert this into fstab for nginx or other uses in your stack:
tmpfs /var/cache/stack_cache tmpfs size=256m,mode=0775,uid=www-data,gid=www-data 0 0
Creating a tmpfs would be a headache because it's only usable by root, and it is, well, temp. I've been down this rabbit hole.

Most flavors of Linux offer tmpfs device which any user can use called /dev/shm. It is not mounted to a specific directory by default, but you can still use it as one. Just create a directory in /dev/shm and then symlink it to wherever you want. You can give the created directory any permissions you choose, so that www-data and PHP users can use it.
This is a RAM backed device, so what's there is in memory by default. You can create any directories you need inside /dev/shm Naturally, files placed here will not survive a reboot, and if your machine starts swapping, /dev/shm won't help you.

@GwynethLlewelyn
Copy link
Author

Whoops. Sorry. I sort of get lost with all threads waiting for my input... and this one has been around for two years. Ugh!

Note that I originally suggested this as an option — not as a default setting — which, as you so well pointed out, could be a really bad idea.

However, there are many other weird and potentially dangerous options on the script... if you don't know what they're for. That's why they are options...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants