1. Output of caddy version
:
v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=
2. How I run Caddy:
Caddy is being run on Ubuntu 20.04.4 LTS on a Linode.
I use a ‘general’ Caddyfile and then import separate domain Caddyfiles which have the content of the general file imported into each of them as required (see below)
a. System environment:
I am using 2 compiled Golang binaries, one front-end and one back-end.
b. Command:
I simply start and stop Caddy as follows after each config change…
sudo service caddy stop
sudo service caddy start
c. Service/unit/compose file:
N/A
d. My complete Caddy config:
General config:
{
email my.email@gmail.com
}
(static) {
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.json
}
header @static Cache-Control max-age=2592000
}
(security) {
header {
# enable HSTS
Strict-Transport-Security max-age=31536000;
# disable clients from sniffing the media type
X-Content-Type-Options nosniff
# keep referrer data off of HTTP connections
Referrer-Policy no-referrer-when-downgrade
}
}
import conf.d/*.conf
Specific example domain config for this case (as imported)
www.example.org, example.org {
encode zstd gzip
import static
import security
# used only when serving static index.html
# root * /var/www/example.org
# file_server
log {
output file /var/log/caddy/example.org-access.log
}
reverse_proxy http://localhost:8090
# @options {
# method OPTIONS
# }
# header {
# Access-Control-Allow-Origin *
# Access-Control-Allow-Credentials true
# Access-Control-Allow-Methods *
# Access-Control-Allow-Headers *
# defer
# }
reverse_proxy * {
to http://localhost:8091
header_down Access-Control-Allow-Origin *
# defer
}
# respond @options 204
}
3. The problem I’m having:
Ok, I will need to explain the above ! My ‘general’ Caddyfile causes no issues, it’s commonly in use with other domains served from this Linode.
The front-end reverse_proxy (:8090) serves correctly. The config code following that (much of which is commented out as a result of trying a multitude of different ideas) relating to the back-end is the problem. I know it probably looks pretty silly but what’s uncommented is where it stands at the moment and leaving the commented-out stuff gives you some idea of where I’ve been going (or not) with this. I just don’t know what to do next.
4. Error messages and/or full log output:
$ journalctl -u caddy --no-pager | less +G yields no entries.
Browser console outputs:
…on attempting to pass authentication and fetch reply from back-end.
Paste logs/commands/output here.
Currently nothing to add here.
5. What I already tried:
None of my attempts at writing a config to allow free flow between front-end (:8090) and back-end (:8091) succeed. All result in CORS failure. I suspect this will turn out to be just a simple configuration statement to reverse_proxy the back-end while accommodating CORS but I haven’t hit on it yet after several hours of attempts. What should I be doing to achieve this please ?
6. Links to relevant resources:
None at present, I have found no links which cover Caddy v2 and CORS together in detail.