In shinsenter/statamic, glide is broken in Statamic 5 due to nginx rule
Closed this issue · 8 comments
docker image: https://hub.docker.com/r/shinsenter/statamic
When using {{ glide }}
the URLs it generates start with /img/
and out of the box this returns an nginx 404 with Statamic 5.
To fix this, I added this to my dockerfile:
FROM shinsenter/statamic:latest-alpine
# ...
# Update nginx config to fix statamic glide /img/
RUN sed -i '/include \/etc\/nginx\/custom.d\/\*.conf;/i \
location ~* ^/img/(.*) {\
try_files $uri @glide;\
}\
location @glide {\
rewrite ^/img/(.*)$ /index.php?/img/$1 last;\
}' /etc/nginx/sites-enabled/00-default.conf
# Test the Nginx configuration
RUN nginx -t
There also seems to be an issue with some images generating 400 errors, 'Signature Invalid'. Investigating that related issue, but the above got glide images working mostly.
More info on this issue: statamic/cms#10053
Hi @replete,
Thank you for providing the information about the new update of Statamic.
I will take some time to review it and update the Docker images, but it will take a little while for the Docker images to be fully updated. In the meantime, please use your current configuration for the projects.
I will notify you once the Docker images are fully updated.
I hope you understand and can be patient.
Hi @shinsenter, Thanks for responding. I'm grateful for the Docker images to get me up and running with Statamic 5 in my developer environment. I'm guessing they just aren't heavily tested with the the latest major release of Statamic, which is understandable as it's not widely used (although I think one of the best CMS).
There are a few other issues I haven't figured out yet, but they all seem to be nginx related:
- Some images generate 400 HTTP errors for glide, I haven't figured that out yet but I think its source filesize issue.
As the production type issues are nginx related, what method do you recommend for configuration? I used sed in this example as a quick hack to try and fix it. Is there a better way to patch nginx.conf, use a volume for /etc/nginx?
Hi @replete.
I'm not very familiar with Statamic 5 and haven't worked on any significant projects using this framework, so it's difficult for me to replicate your issue and provide an effective solution.
If you could provide me with a small project along with the steps to reproduce and test the cases you're mentioning, I think it would be very helpful and would allow me to come up with a solution more quickly.
Best regards
Thanks for your response. This is my first Statamic site so I'm working on a project and also trying to figure out how I'm going to deploy this to production and evaluate whether I can use this realistically use this image in production. I'm wondering if I need to make my own image because there's an abstraction here that I think could cause me problems especially if you aren't that familiar with statamic
I could put together a repo like this for specific issues, but there are likely to be more of them and it doesn't make sense for me to have a dependency on the docker image maintainer to fix my site.
I think there are likely to be nginx configuration specifics to solve these issues, and it doesn't make sense to wait for you each time something isn't working. Also what happens when Statamic 6 comes out, it auto upgrades and some specific thing needs to change.
But if you can recommend how I can best change nginx.conf using a Dockerfile FROM e.g. FROM shinsenter/statamic:latest-alpine
, I can then share my fixes with you, and explain what they do?
What I'm expecting to need to make this image realistically production ready:
- limit PHP version, e.g. 8.3 to prevent unexpected site breakages
- have more control over nginx configuration
- implement some kind of periodic letsencrypt certificate generation
By the way, I have made a few minor updates to my Docker images, and I would like to know if they can solve your current problem.
Previously, to optimize requests for static files like images, I did not let them go through PHP processing. However, many modern frameworks have functions to generate various contents and use friendly URLs just like static files, so I have now routed image requests through PHP processing in case the file does not exist on the server.
Amazing, thanks so much Shin, this has fixed the HTTP issues with glide images, which was the main pain point.
Cảm ơn Shin, bạn là người tuyệt vời nhất!
Thank you for the kind words. 😉