[英]How to serve static files with Caddy next to PHP Script execution? (Symfony)
I have a docker-compose based Server setup running PHP, Postgres and Caddy as Webserver/Reverse-Proxy with Auto-SSL that serves a PHP-Application (Framework Symfony 3/Sylius 1.5) with php5-fpm.我有一个基于 docker-compose 的服务器设置,运行 PHP,Postgres 和 Caddy 作为 Web 服务器/反向代理,带有自动 SSL,服务于带有 php5-fpm 的 PHP 应用程序(框架 Symfony 3/Sylius 1.5)。
It works very well so far, but not with any static files like CSS, Images, JS and so on, although the file_server
directive was placed.到目前为止,它工作得很好,但不适用于任何 static 文件,如 CSS、图像、JS 等,尽管放置了file_server
指令。 Any static content gets a 404.任何 static 内容都会得到 404。
My application is copied into the folder /srv/app
, where /srv/app/public
contains index.php
and /srv/app/public/assets
contains static files (including several sub-folders).我的应用程序被复制到文件夹/srv/app
中,其中/srv/app/public
包含index.php
和/srv/app/public/assets
包含 static 文件(包括几个子文件夹)。
This is my Caddyfile:这是我的 Caddyfile:
{$SERVER_NAME}
log
route {
root * /srv/app/public
php_fastcgi unix//var/run/php/php-fpm.sock
encode zstd gzip
file_server
}
I have tried to specify folders for file_server
directive like:我试图为file_server
指令指定文件夹,例如:
file_server assets/
or或者
file_server assets {
}
each within the route
-branch.每个在route
分支内。
But this way, Caddy won't serve anything and gives 500er.但是这样,Caddy 不会提供任何东西并提供 500er。
How can I fix this?我怎样才能解决这个问题?
For me, something like this worked (why this way, I don't know).对我来说,这样的事情有效(为什么这样,我不知道)。
Directory is:目录是:
/projects/site
-- static
----- jquery
--------- jquery.js
index.php
Site can be accessed as: http://1.2.3.4:8000/site站点可以访问为: http://1.2.3.4:8000/site
Static files are requested under eg: http://1.2.3.4:8000/site/static/jquery/jquery.js Static 文件请求如下: http://1.2.3.4:8000/site/static/jquery/jquery.js
:8000 {
root * /projects/site
@path {
not path /site/static*
path /site*
}
log {
output file /var/log/caddy/site.log
}
handle_path /site/static* {
root * /projects/site/static
file_server
}
php_fastcgi @path unix//run/php/php5.6-fpm.sock
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.