Cors error when I try to upload files

1. Caddy version (caddy version):


2. How I run Caddy:


a. System environment:

Ubuntu Debian 4.19.232-1

b. Command:

sudo caddy run

c. My complete Caddyfile or JSON config:


(cors) {
	@origin{args.0} header Origin {args.0}
	header @origin{args.0} Access-Control-Allow-Origin "{args.0}"
}, {
	root /index.html /home/ronnie/meemzv2/meemz/build
	import cors
}, {
	root * /home/ronnie/meemzv2
	import cors
}, {
	root * /home/ronnie/chat_server
	header {
		Access-Control-Allow-Credentials true

3. The problem I’m having:

Everytime I tried uploading files, I got a cors error. I added cors to my plugin and I no longer get a cors error, I get a 502 error.

4. Error messages and/or full log output:

2022/03/25 09:03:43.336 ERROR http.log.error EOF {“request”: {“remote_addr”: “”, “proto”: “HTTP/2.0”, “method”: “POST”, “host”: “”, “uri”: “/convo_banner_upload”, “headers”: {“Sec-Ch-Ua”: ["" Not A;Brand";v=“99”, “Chromium”;v=“99”, “Google Chrome”;v=“99"”], “Sec-Ch-Ua-Platform”: ["“Linux”"], “Sec-Fetch-Site”: [“cross-site”], “Sec-Fetch-Mode”: [“cors”], “Accept-Encoding”: [“gzip, deflate, br”], “User-Agent”: [“Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36”], “Origin”: [“”], “Accept”: [“application/json, text/plain, /”], “Content-Type”: [“multipart/form-data; boundary=----WebKitFormBoundaryQVzeO6XUAbv6aSMl”], “Sec-Fetch-Dest”: [“empty”], “Referer”: [“”], “Content-Length”: [“9905”], “Sec-Ch-Ua-Mobile”: ["?0"], “Accept-Language”: [“en-US,en;q=0.9”]}, “tls”: {“resumed”: false, “version”: 772, “cipher_suite”: 4865, “proto”: “h2”, “proto_mutual”: true, “server_name”: “”}}, “duration”: 0.079547563, “status”: 502, “err_id”: “kc8k9vujm”, “err_trace”: “reverseproxy.statusError (reverseproxy.go:886)”}

5. What I already tried:

I tried fixing the cors problem in my backened

Is your expectation that this:

  1. Goes to the client/remtoe user, or
  2. Goes to the proxied service?

My expectation is the uploaded file to go to the vms fs. I already tried that but now I’m getting a 502.

Wait, hold on - do be patient - we will get there. Yes, I understood this objective from your OP but to get there we need to solve some smaller things first.

So my question here is, when you wrote:

Were your expecting that this configuration would:

  1. Go to the client/remote end user (downstream), or
  2. Goes to the proxied service (upstream)?

Which one of 1, 2 or, something else entirely?

1 Like

This configuration was to go to the end user.

I think there’s a logic problem in the config.

You have both root + file_server, and reverse_proxy, but you’re not using any request matchers to tell Caddy when to use file_server instead of reverse_proxy.

The Caddyfile orders reverse_proxy before file_server, so with that setup, reverse_proxy will be handling all requests to those domains, and file_server will never do anything.

What exactly are you trying to do? What requests do you need to go where? Share some example curl -v requests that you’re trying to perform, and explain what you expect to happen for each.


I’m kinda new to this. I didn’t know I can do that. I’m trying to upload images to the server which will make api calls to a Google’s server and send back a response which will be stored in a database. Kindly show me how this is done.

We will be happy to - can you answer what francislavoie requested here:

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.