Changing nginx to caddy

I’m going to switch from nginx reverse proxy to reverse proxy caddy soon. I have no problem with nginx, everything works well even with the certbot plugin (tls, subdomain, wildcard *). I have studied the caddy documentation quite a bit and it seems that everything is almost automatic. I own several domains including wildcard *. Apparently the caddy configuration is very simple. For example for example.com

example.com {
  reverse_proxy 192.168.20.11
}

My configuration for the domain example.com (including www) looks like this in nginx

server {
    server_name example.com;
    return 301 http://www.example.com$request_uri;
 
    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-<span class="search_hit">nginx</span>.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header Referrer-Policy                      "no-referrer"   always;
    add_header X-Content-Type-Options               "nosniff"       always;
    add_header X-Download-Options                   "noopen"        always;
    add_header X-Frame-Options                      "SAMEORIGIN"    always;
    add_header X-Permitted-Cross-Domain-Policies    "none"          always;
    add_header X-Robots-Tag                         "none"          always;
    add_header X-XSS-Protection                     "1; mode=block" always;
    add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;
    add_header Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()";
 
}
  
server {
    server_name www.example.com;
  
    location / {
        proxy_pass http://192.168.1.101;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    client_max_body_size 32M;
    }
 
    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-<span class="search_hit">nginx</span>.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header Referrer-Policy                      "no-referrer"   always;
    add_header X-Content-Type-Options               "nosniff"       always;
    add_header X-Download-Options                   "noopen"        always;
    add_header X-Frame-Options                      "SAMEORIGIN"    always;
    add_header X-Permitted-Cross-Domain-Policies    "none"          always;
    add_header X-Robots-Tag                         "none"          always;
    add_header X-XSS-Protection                     "1; mode=block" always;
    add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;
    add_header Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()";
}
 
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
 
 
    listen 80;
    server_name example.com;
    return 404; # managed by Certbot
 
 
}
  
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
 
 
    listen 80;
    server_name www.example.com;
    return 404; # managed by Certbot
 
 
}

I don’t really need much.
Solve the let’s encrypt certificates (according to the caddy documentation, it all happens automatically).

Redirect to www
This means that if the client types in the url example.com, it will be redirected to www.example.com.

Next, I need to resolve the DNS challenge, because I have many *.example.com subdomains (including private subdomains).
My domains are on cloudflare, noip.com and changeip.com (subdomains are only on clouflare). I hope I can manage it and there will be no problems, because the caddy looks very good.
I still have a dilemma whether to use docker in LXC or use LXC debain and apt.
I plan to allocate 1x LXC 2 CPU core, 512 MB RAM for the caddy.

1 Like

Most of your questions are answered by this page:

See here:

1 Like

Thank you very much, I will try

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