Cors error when I try to upload files

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

Domian: https://meemz.cf

a. System environment:

Ubuntu Debian 4.19.232-1

b. Command:

sudo caddy run

c. My complete Caddyfile or JSON config:

{
	admin 127.0.0.1:2002
}

(cors) {
	@origin{args.0} header Origin {args.0}
	header @origin{args.0} Access-Control-Allow-Origin "{args.0}"
}

meemz.cf, www.meemz.cf {
	root /index.html /home/ronnie/meemzv2/meemz/build
	reverse_proxy 127.0.0.1:3000
	import cors https://meemzapi.cf
	file_server
}

meemzapi.cf, www.meemzapi.cf {
	root * /home/ronnie/meemzv2
	reverse_proxy 127.0.0.1:3001
	import cors https://meemz.cf
	file_server
}

meemzchat.cf, www.meemzchat.cf {
	root * /home/ronnie/chat_server
	reverse_proxy 127.0.0.1:3002
	header {
		Access-Control-Allow-Origin https://meemzapi.cf
		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”: “154.122.111.225:53558”, “proto”: “HTTP/2.0”, “method”: “POST”, “host”: “meemzapi.cf”, “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”: [“https://meemz.cf”], “Accept”: [“application/json, text/plain, /”], “Content-Type”: [“multipart/form-data; boundary=----WebKitFormBoundaryQVzeO6XUAbv6aSMl”], “Sec-Fetch-Dest”: [“empty”], “Referer”: [“https://meemz.cf/”], “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”: “meemzapi.cf”}}, “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.

2 Likes

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.