Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#289 2020-06-25 14:36:48
Re: Textpattern CMS demo site
etc wrote #324016:
Me, but it works locally.
I think I know how you did that. I should probably lock that down.
Offline
#290 2020-06-25 14:38:03
Offline
#291 2020-06-25 14:45:21
Re: Textpattern CMS demo site
Well, this is a problem. Branches-as-subdirectories needs some work, Nginx throws errors as my current config doesn’t recognise /branch/articles
and needing to resolve to /branch
for the index.php
. Ugh.
I’ll need to unpick this. Might take a while.
Offline
#292 2020-06-25 15:05:18
Re: Textpattern CMS demo site
Offline
#293 2020-06-25 15:13:35
Re: Textpattern CMS demo site
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#294 2020-06-25 15:21:05
Re: Textpattern CMS demo site
Offline
#295 2020-06-25 15:34:30
Re: Textpattern CMS demo site
colak wrote #324022:
All works fine from here
Thanks, Yiannis!
Anyone interested in the fix? Here goes.
Typically I install Textpatterns in the root of a domain, and the Nginx magic that binds the index.php
to the site is in two parts:
location / {
index index.html index.php;
limit_except GET HEAD POST {
deny all;
}
try_files $uri $uri/ /index.php$is_args$args;
}
To translate as best I can: the location
block tells Nginx that everything inside refers to URLs that hang off /
, the index
line looks for index.html
first, then checks for index.php
, the limit_except
block denies any HTTP requests that aren’t GET
, HEAD
or POST
, and the try_files
line tells Nginx to first try the URI as provided, then try the same thing with a trailing slash if the raw URI fails, then try /index.php
as the final fallback. In real terms, if I have actual directories in the Textpattern site (e.g. /banana/
, /music/
, /oleg-keep-out/
) they will be used in preference to, say, a Textpattern section.
This all works A-OK if the Textpattern hangs off the domain root. However, when you get ideas above your station and think “Hey, I bet it would be neat to have GitHub branches as subdirectories”, you need to remember that THIS WILL NOT WORK and you need the following (example for dev
branch):
location /dev/ {
try_files $uri $uri/ /dev/index.php$is_args$args;
}
So…Nginx now has a /dev/
subdirectory block. It inherits the location
directives from the first block above, so all that still works fine (index
, try_files
is all relevant to this new block), but crucially the index.php
it refers to is not in the root. The correct index.php
is in /dev/
. This location
block inherits all the higher-up directives from /
, but uses its own try_files
to replace the one it inherited.
(Thanks for coming to my TED talk.)
Offline
#296 2020-06-25 15:53:18
Re: Textpattern CMS demo site
hits subscribe to @petecooper talks button
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#297 2020-06-25 16:11:50
Re: Textpattern CMS demo site
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#298 2020-06-25 17:14:42
Re: Textpattern CMS demo site
I will admit I clicked play.
Offline
#299 2020-06-25 17:27:12
Re: Textpattern CMS demo site
gaekwad wrote #324024:
Typically I install Textpatterns in the root of a domain, and the Nginx magic that binds the
index.php
to the site is in two parts:
location / {...
If you were thinking “But, Pete – that’s only one part of Nginx magic, what about the other part that includes a scary regex and some glue to make PHP-FPM work?”, then wonder no more! Look:
location ~ ^.+\.php(?:/.*)?$ {
fastcgi_hide_header "X-Powered-By";
fastcgi_keep_conn on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php-fpm74.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
try_files $uri =404;
}
This…took me a while to get right. It’s a location block to funnel any PHP requests through FastCGI and, given the right love and attention, is wicked-fast and seems secure. The fastcgi_pass
line is the clever stuff that allows multiple versions of PHP on one server, and each site can use one of the installed versions. Local file socket (the .sock
part) is faster than a localhost IP:port setup as there’s less overhead.
The main downside to PHP-FPM is…well, I’m still learning how to make PHP performant, and when things get very busy there are some occasions where PHP-FPM panics and stops. No errors in the log. Just…done.
And what is Pete’s actually-quite-clever-when-you-think-about-it solution? Well, dear reader, I’m glad you asked. I have set up PHP-FPM to run on the external IP addresses and localhost. So, you hit PHP-FPM when you access the Textpattern sites, and that works fine…and every n minutes I have a shell script run a curl
task to check the HTTP headers of a PHP-FPM status on 127.0.0.1 (one port per version of PHP). If there’s a 200 OK
status, nothing happens. If there’s anything else, it automatically restarts PHP-FPM, waits 5 seconds and tries again. 99% of the time it works seamlessly, but that 1% that it doesn’t, I get an alert email.
(Thanks for listening to my sysadmin ASMR, there’s a merch stand at the back of the hall.)
Offline
#300 2020-06-25 17:42:37
Re: Textpattern CMS demo site
That’s some cool tech there, Sir. I’ve never delved into PHP-FPM . I really should. But then I’ve not used Nginx in anger either. Just once, and that was pretty much default-leave-it-and-run-away. Note to self: learn more.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline