Serious doubts about my www handling

1. The problem I’m having:

Using www on my domain didn’t work and I fixed that.
However I have serious doubts about my approach and I wondered if someone can have a look. If somone does not specify www then I still wan’t it to go to the www version.

2. Error messages and/or full log output:

No errors…

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

I can’t remember how I installed.

curl localhost:2019/load -H "Content-Type: application/json" -d @/home/doeke/Desktop/_DONT_MOVE_THIS_FOLDER_OR_ANYTHING_IN_IT_/caddy.json

a. System environment:

Ubuntu 22.04.3 LTS

b. Command:

curl localhost:2019/load -H "Content-Type: application/json" -d @/home/doeke/Desktop/_DONT_MOVE_THIS_FOLDER_OR_ANYTHING_IN_IT_/caddy.json

Important note!!!
I can set a subdomain with my DNS settings on my hosting. I set them to www now, I didn’t have that before. It might take some time to get into effect.

Hope someone can help.

(and yeah maybe I should switch to using Caddyfile…).



{
	"apps": {
		"http": {
			"servers": {
				
				"=== HSLAB === & === DOEKE_WARTENA ===": {
					"listen": [":443"],
					"routes": [
						{
							"match":
								[ {"host": ["hslab.nl", "doekewartena.nl", "nc.doekewartena.nl"]} ],
							"handle": [
								{
									"handler": "static_response",
									"headers": {
										"Location": [
											"http://www.{http.request.host}{url}"
										]
									},
									"status_code": 302
								}
							],
							"terminal": true
						},
						{ 
							"match": 
								[ {"host": ["www.hslab.nl"]} ],
							"handle": [
								{
									"handler": "static_response",
								  "body": "hslab"
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": ["www.doekewartena.nl"]
								}
							],
							"handle": [
								{
									"handler": "static_response",
									"body": "doekewartena"
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": ["www.nc.doekewartena.nl"]
								}
							],
							"handle": [
								{
									"handler": "reverse_proxy",
									"upstreams": [
										{
											"dial": "localhost:81"
										}
									]
								}
							],
							"terminal": true
						}

					]		
				}	
			}
		}
	}
}

Yeah, certainly much easier to write config with Caddyfile.

You can use the caddy adapt command after writing a Caddyfile to convert it to JSON if you have a good reason to use a JSON config.

I don’t really understand what problem you’re having. You didn’t show any logs or describe an actual problem, so I don’t know what to tell you.

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