lemmy icon indicating copy to clipboard operation
lemmy copied to clipboard

Add Apache and Caddy config templates

Open scarlet-tobar opened this issue 4 years ago • 13 comments

I was looking for webserver sample .conf files but it seems there's only one for nginx. Would it be possible to make more for other webservers?

Thanks.

scarlet-tobar avatar Jun 16 '20 22:06 scarlet-tobar

Here's a starting point for Caddy - I haven't been able to test it because I'm trying to run the docker-compose on a Pi4 and I can't find an ARM64 build for iFramely, but it should save you some work at least.

Note that it requires Caddy 2.1 since it uses handle_path:

lemmy.yourdomain.com {
    import common
    route {
        @pictshare {
            path_regexp img /pictshare/(.*)
        }
        redir @pictshare /pictrs/image/{http.regexp.img.1} permanent

        handle_path /pictrs/* {
            reverse_proxy /image pictrs:8080
            respond 403
        }

        reverse_proxy /iframely iframely:80
        reverse_proxy lemmy:8536
    }
}

where common is a snippet of default settings I use:

(common) {
    log {
       output file /data/logs/caddy.log
    }
    encode gzip
    header {
        -Server
        Strict-Transport-Security "max-age=31536000; include-subdomains;"
        X-XSS-Protection "1; mode=block"
        X-Frame-Options "DENY"
        X-Content-Type-Options nosniff
        Referrer-Policy no-referrer-when-downgrade
        X-Robots-Tag "none"
    }
}

piaste avatar Jun 30 '20 15:06 piaste

Lemmy should also work without iframely, it will just be unable to generate link previews. We could also make the iframely URL configurable, then you could use dev.lemmy.ml/iframely.

Nutomic avatar Jul 01 '20 12:07 Nutomic

I'll re-open if anyone works on / starts adding these.

dessalines avatar Aug 11 '20 20:08 dessalines

Hello, I am also trying to run Lemmy and Caddy. But I don't know how? Can anyone help me

DokStook avatar Jul 28 '22 13:07 DokStook

We won't support any server but nginx, but if anyone wants to submit templates for others, feel free to. I'll leave this open.

dessalines avatar Jul 28 '22 14:07 dessalines

We won't support any server but nginx, but if anyone wants to submit templates for others, feel free to. I'll leave this open.

Okay, that does it, I wanted to run my own instance but this single comment convinced me otherwise. Not only you cannot resolve !2201 by the single fix I "invented" today (which prevents me from building from sources) but also the official freaking docu on "Install with Docker" says plainly: "Make sure you have both docker and docker-compose(>=1.24.0) installed". And guess what? Then you use "restart: always" which yields an error and was fixed somewhere in 2.x.y. BYE LEMMY, I'M DONE

paboum avatar Oct 25 '22 01:10 paboum

(caddy-common) {
    encode gzip
    header {
        -Server
        Strict-Transport-Security "max-age=31536000; include-subdomains;"
        X-XSS-Protection "1; mode=block"
        X-Frame-Options "DENY"
        X-Content-Type-Options nosniff
        Referrer-Policy  no-referrer-when-downgrade
        X-Robots-Tag "none"
    }
}

lemmy-site.com {
        import caddy-common
        reverse_proxy   http://lemmy_lemmy-ui_1:1234
}

@lemmy {
        path    /api/*
        path    /pictrs/*
        path    /feeds/*
        path    /nodeinfo/*
        path    /.well-known/*
}

@lemmy-hdr {
        header Accept application/*
}

handle @lemmy {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

handle @lemmy-hdr {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

@lemmy-post {
        method POST
}

handle @lemmy-post {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

seems to be working

nycterent avatar Dec 22 '22 15:12 nycterent

@nycterent Could you please make a pull request to add it to the documentation?

Nutomic avatar Dec 22 '22 16:12 Nutomic

(caddy-common) {
    encode gzip
    header {
        -Server
        Strict-Transport-Security "max-age=31536000; include-subdomains;"
        X-XSS-Protection "1; mode=block"
        X-Frame-Options "DENY"
        X-Content-Type-Options nosniff
        Referrer-Policy  no-referrer-when-downgrade
        X-Robots-Tag "none"
    }
}

lemmy-site.com {
        import caddy-common
        reverse_proxy   http://lemmy_lemmy-ui_1:1234
}

@lemmy {
        path    /api/*
        path    /pictrs/*
        path    /feeds/*
        path    /nodeinfo/*
        path    /.well-known/*
}

@lemmy-hdr {
        header Accept application/*
}

handle @lemmy {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

handle @lemmy-hdr {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

@lemmy-post {
        method POST
}

handle @lemmy-post {
        reverse_proxy   http://lemmy_lemmy_1:8536
}

seems to be working

This isn't for caddy 2 though, right?

paulo-roger avatar Jun 17 '23 14:06 paulo-roger

i am using it with v2.6.4. are you having any issues with it?

On Sat, Jun 17, 2023 at 4:59 PM paulo-roger @.***> wrote:

(caddy-common) { encode gzip header { -Server Strict-Transport-Security "max-age=31536000; include-subdomains;" X-XSS-Protection "1; mode=block" X-Frame-Options "DENY" X-Content-Type-Options nosniff Referrer-Policy no-referrer-when-downgrade X-Robots-Tag "none" } } lemmy-site.com { import caddy-common reverse_proxy http://lemmy_lemmy-ui_1:1234 }

@lemmy { path /api/* path /pictrs/* path /feeds/* path /nodeinfo/* path /.well-known/* }

@lemmy-hdr { header Accept application/* }

handle @lemmy { reverse_proxy http://lemmy_lemmy_1:8536 }

handle @lemmy-hdr { reverse_proxy http://lemmy_lemmy_1:8536 }

@lemmy-post { method POST }

handle @lemmy-post { reverse_proxy http://lemmy_lemmy_1:8536 }

seems to be working

This isn't for caddy 2 though, right?

— Reply to this email directly, view it on GitHub https://github.com/LemmyNet/lemmy/issues/819#issuecomment-1595780061, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATZ3KXPZBAPAXJVHPYBHDXLXA57ANCNFSM4OABNTZA . You are receiving this because you were mentioned.Message ID: @.***>

nycterent avatar Jun 17 '23 15:06 nycterent

i am using it with v2.6.4. are you having any issues with it? On Sat, Jun 17, 2023 at 4:59 PM paulo-roger @.> wrote: (caddy-common) { encode gzip header { -Server Strict-Transport-Security "max-age=31536000; include-subdomains;" X-XSS-Protection "1; mode=block" X-Frame-Options "DENY" X-Content-Type-Options nosniff Referrer-Policy no-referrer-when-downgrade X-Robots-Tag "none" } } lemmy-site.com { import caddy-common reverse_proxy http://lemmy_lemmy-ui_1:1234 } @lemmy { path /api/ path /pictrs/ path /feeds/ path /nodeinfo/* path /.well-known/* } @lemmy-hdr { header Accept application/* } handle @lemmy { reverse_proxy http://lemmy_lemmy_1:8536 } handle @lemmy-hdr { reverse_proxy http://lemmy_lemmy_1:8536 } @lemmy-post { method POST } handle @lemmy-post { reverse_proxy http://lemmy_lemmy_1:8536 } seems to be working This isn't for caddy 2 though, right? — Reply to this email directly, view it on GitHub <#819 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATZ3KXPZBAPAXJVHPYBHDXLXA57ANCNFSM4OABNTZA . You are receiving this because you were mentioned.Message ID: @.***>

yes, I get the following error:

Job for caddy.service failed because the control process exited with error code. See "systemctl status caddy.service" and "journalctl -xe" for details.

Error: adapting config using caddyfile: cannot define a matcher outside of a site block: '@lemmy'

paulo-roger avatar Jun 17 '23 17:06 paulo-roger

try this:

lemmy-site.com {
        import caddy-common
        reverse_proxy   http://lemmy_lemmy-ui_1:1234

        @lemmy {
                path    /api/*
                path    /pictrs/*
                path    /feeds/*
                path    /nodeinfo/*
                path    /.well-known/*
        }

        @lemmy-hdr {
                header Accept application/*
        }

        handle @lemmy {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }

        handle @lemmy-hdr {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }

        @lemmy-post {
                method POST
        }

        handle @lemmy-post {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }
}

nycterent avatar Jun 17 '23 18:06 nycterent

Yeah! Only thing I had to change was reverse_proxy localhost:1234

Thank you very much!

paulo-roger avatar Jun 19 '23 00:06 paulo-roger

Hi @nycterent I recently had a problem with an user uploading huge pics, I have just learned I can limit it in caddy.

I just added this

lemmy-site.com {
    import caddy-common
    reverse_proxy   localhost:1234
# Adding max size upload to 256kb 
    request_body {
      max_size 256KB 
    }
  ...

paulo-roger avatar Jun 29 '23 22:06 paulo-roger

good idea ;)

On Fri, Jun 30, 2023 at 12:45 AM paulo-roger @.***> wrote:

Hi @nycterent https://github.com/nycterent I recently had a problem with an user uploading huge pics, I have just learned I can limit it in caddy.

I just added this

lemmy-site.com { import caddy-common reverse_proxy localhost:1234

Adding max size upload to 256kb

request_body {
  max_size 256KB
}

...

— Reply to this email directly, view it on GitHub https://github.com/LemmyNet/lemmy/issues/819#issuecomment-1613890696, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATZ3MFENA3EB5XGX44OGTXNYAQLANCNFSM4OABNTZA . You are receiving this because you were mentioned.Message ID: @.***>

nycterent avatar Jun 30 '23 13:06 nycterent

try this:

lemmy-site.com {
        import caddy-common
        reverse_proxy   http://lemmy_lemmy-ui_1:1234

        @lemmy {
                path    /api/*
                path    /pictrs/*
                path    /feeds/*
                path    /nodeinfo/*
                path    /.well-known/*
        }

        @lemmy-hdr {
                header Accept application/*
        }

        handle @lemmy {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }

        handle @lemmy-hdr {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }

        @lemmy-post {
                method POST
        }

        handle @lemmy-post {
                reverse_proxy   http://lemmy_lemmy_1:8536
        }
}

What is the difference between this one and the one before that? The latter has the @ -handle clauses inside the lemmy-site specification, while the former does not. How do these two differ in their operations?

k4r4b3y avatar Jul 19 '23 11:07 k4r4b3y

if i remember correctly - non working one had issues with missing curly bracket. the fixed version also has improved formatting

nycterent avatar Jul 19 '23 17:07 nycterent

@nycterent can you clarify which Caddyfile you mean "non working" and which "fixed" ?

k4r4b3y avatar Jul 20 '23 12:07 k4r4b3y

@nycterent can you clarify which Caddyfile you mean "non working" and which "fixed" ?

sorry - https://github.com/LemmyNet/lemmy/issues/819#issuecomment-1595823157 is working one.

nycterent avatar Jul 21 '23 16:07 nycterent

These would live in the lemmy-docs repo, not here.

dessalines avatar Oct 18 '23 19:10 dessalines