My config not working

My Caddyfile this:

header / {
	# Enable HTTP Strict Transport Security (HSTS) to force clients to always
	# connect via HTTPS (do not use if only testing)
	Strict-Transport-Security "max-age=31536000;"
	# Enable cross-site filter (XSS) and tell browser to block detected attacks
	X-XSS-Protection "1; mode=block"
	# Prevent some browsers from MIME-sniffing a response away from the declared Content-Type
	X-Content-Type-Options "nosniff"
	# Disallow the site to be rendered within a frame (clickjacking protection)
	X-Frame-Options "DENY"
        -Server
}
my.domain{
proxy / backend_ip:80
}

In bash i see this error:
Caddyfile:4 - Error during parsing: Unknown directive ‘Strict-Transport-Security’

I try this:

my.domain{
proxy / backend_ip:80
}
header / {
	# Enable HTTP Strict Transport Security (HSTS) to force clients to always
	# connect via HTTPS (do not use if only testing)
	Strict-Transport-Security "max-age=31536000;"
	# Enable cross-site filter (XSS) and tell browser to block detected attacks
	X-XSS-Protection "1; mode=block"
	# Prevent some browsers from MIME-sniffing a response away from the declared Content-Type
	X-Content-Type-Options "nosniff"
	# Disallow the site to be rendered within a frame (clickjacking protection)
	X-Frame-Options "DENY"
        -Server
}

Bash also again send error:
Caddyfile:7 - Error during parsing: Unknown directive ‘Strict-Transport-Security’

Install caddy from this command line:
curl https://getcaddy.com | bash -s personal hook.service,http.cache,http.cors,http.expires,http.filebrowser,http.filter,http.forwardproxy,http.geoip,http.ipfilter,http.locale,http.login,http.minify,http.nobots,http.proxyprotocol,http.ratelimit,http.realip,http.reauth,http.restic,http.s3browser,http.supervisor,http.upload,supervisor

Please help!

Hi @Alex_Kim, welcome to the Caddy community!

I formatted your post to include code blocks (```) around your Caddyfile and the curl command you used to install Caddy.

You haven’t correctly formatted your Caddyfile. Review the Caddyfile tutorial:

The first line of the Caddyfile is always the address of the site to serve.

https://caddyserver.com/tutorial/caddyfile

You can’t use a directive like header as a top-level element in your Caddyfile.

1 Like

Thank you!I start first project reverse proxy an Caddy, this very easy!

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