Closed ryan-marshall-evident closed 11 months ago
I cannot reproduce. This looks like a Docker container (judging by the hostname). Could you share a Dockerfile that exhibits this behaviour?
Here's a stripped-down docker file I've tested this on:
FROM unit:1.31.0-php8.2@sha256:3489384ba2bdfa707d08431b335b0f776c206863e93e5998892199036d767468 as dev
COPY <<EOF /docker-entrypoint.d/config.json
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"action": {
"share": "/www/public$uri"
}
}
],
"settings": {
"http": {
"log_route": true
}
}
}
EOF
COPY <<EOF /www/public/file.html
<html>
<head>
<title>Unit</title>
</head>
<body>
<h1>Unit</h1>
<p>Hello world!</p>
</body>
</html>
EOF
WORKDIR /www
EXPOSE 80
Running on docker desktop version 4.24.0 (122432).
I had another look on this. The configuration you are creating in you Dockerfile
will not arrive in your container as you think. $uri
WILL NOT BE interpreted as a string as it includes a $
and therfore it should be variable name.
Simple Test:
COPY <<EOF /tets.txt
abc $123
EOF
$ docker run --rm -it -P tippexs/unit:fi cat /tets.txt
abc
We have to escape the $
to make this work:
COPY <<EOF /docker-entrypoint.d/config.json
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"action": {
"share": "/www/public\$uri"
}
}
],
"settings": {
"http": {
"log_route": true
}
}
}
EOF
Going to close this issue now.
@tippexs, thanks for your response. I've just tested this and it worked a treat. I had a feeling it was going to be something straightforward.
I have been trying to set up a PHP application that also serves static files. Unfortunately, when I request the static assets, I get a 301 redirect to the same file with a
/
appended.So
http://localhost/file.html
redirects tohttp://localhost/file.html/
which redirects tohttp://localhost/file.html//
.I have tried to strip back the configuration to just serve the static files (see config below), however, this still results in the redirects.