Latest Caddy (Point www to non www version)

1. Caddy version (caddy version):

2.4.1

2. How I run Caddy:

caddy loads by default. It was installed using PPA

a. System environment:

Ubuntu 20.04

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

https://opency.com {
# Set this path to your site’s directory.
root * /var/www/opency
# Enable the static file server.
header Access-Control-Allow-Origin “"
header Access-Control-Allow-Methods “POST, GET, OPTIONS, PUT, DELETE”
header Access-Control-Allow-Headers "

file_server
encode gzip zstd
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
try_files {path} {path}/index.php
php_fastcgi localhost:9000
# Refer to the Caddy docs for more information:
# The Caddyfile — Caddy Documentation
@cachedFiles {
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff
}
header @cachedFiles Cache-Control max-age=5184000
}

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

3. The problem I’m having:

4. Error messages and/or full log output:

5. What I already tried:

Tried redir already, does not work

6. Links to relevant resources:

Got confused with so many questions while creating this post. Anyway, The main ones are:

  1. How to redirect www.domain.com to domain.com
  2. How to update the json file of caddy after updating the Caddyfile. Currently I am going in and deleting the caddy json file, then caddy stop, then I go to the /etc/caddy folder and run caddy start
  3. How (if possible) to block outside calls to a specific folder, folders or files, unless the call actually came from the same server. Like a file calls another file on the same server, that is okay. But if a file from the outside tries to call the file directly, it gets a 404.

There are examples here:

You don’t need to do that. After you update your Caddyfile, run sudo systemctl reload caddy

Use the remote_ip matcher.

1 Like

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