From f1d0667b8005bab5e408a8f1fdd934168b327ad9 Mon Sep 17 00:00:00 2001 From: "yakumo.izuru" Date: Sun, 11 Feb 2024 00:56:18 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E6=89=8B=E9=A0=86=E3=81=AE=E6=9B=B4=E6=96=B0=E3=80=81?= =?UTF-8?q?=E4=BE=8B=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=80=81=E3=83=AA=E3=83=9F?= =?UTF-8?q?=E3=83=83=E3=82=BF=E3=83=BC=E3=81=AE=E5=86=8D=E6=A7=8B=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Izuru Yakumo git-svn-id: file:///srv/svn/repo/mai/trunk@68 e410bdd4-646f-c54f-a7ce-fffcc4f439ae --- INSTALL.md | 6 +++--- cmd/mai/main.go | 11 ++++++++++- example/mai.h2o.yml | 16 ++++++++++++++++ example/mai.nginx | 23 +++++++++++++++++++++++ views/429.html | 21 +++++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 example/mai.h2o.yml create mode 100644 example/mai.nginx create mode 100644 views/429.html diff --git a/INSTALL.md b/INSTALL.md index f3ca296..e24d44e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,11 +1,11 @@ # Installation ```shell -$ git clone https://git.chaotic.ninja/yakumo.izuru/mai +$ git clone git://git.chaotic.ninja/yakumo_izuru/mai $ cd mai $ make # make PREFIX=/usr/local install ``` * Read the [mai.ini(5)](mai.ini.5) manual page -* Use any web server than is able to reverse proxy, like Apache, h2o, or NGINX. - +* Use any web server than is able to reverse proxy, like [Apache](https://httpd.apache.org), [h2o](https://h2o.examp1e.net), or [NGINX](https://www.nginx.com). + * Examples are provided on the repository diff --git a/cmd/mai/main.go b/cmd/mai/main.go index 65922bf..f573eee 100644 --- a/cmd/mai/main.go +++ b/cmd/mai/main.go @@ -57,6 +57,8 @@ func main() { app := fiber.New( fiber.Config{ AppName: "Mai", + ProxyHeader: fiber.HeaderXForwardedFor, + TrustedProxies: []string{"0.0.0.0/0"}, ServerHeader: "Mai (using Fiber v2.x)", Views: engine, }) @@ -75,7 +77,14 @@ func main() { }, )) - app.Use(limiter.New()) + app.Use(limiter.New(limiter.Config{ + Max: 10, + Expiration: 180 * time.Second, + LimitReached: func(c *fiber.Ctx) error { + return c.SendStatus(429) + return c.SendFile(conf.tmplpath + "/429.html") + }, + })) app.All("/", func(c *fiber.Ctx) error { engine := c.Cookies("engine") diff --git a/example/mai.h2o.yml b/example/mai.h2o.yml new file mode 100644 index 0000000..aced81e --- /dev/null +++ b/example/mai.h2o.yml @@ -0,0 +1,16 @@ +hosts: + "mai.example.net:80": + listen: + port: 80 + paths: + "/": + redirect: mai.example.net:443 + "mai.example.net:443": + listen: + port: 443 + ssl: + certificate-file: /path/to/fullchain.pem + key-file: /path/to/privkey.pem + paths: + "/": + proxy.reverse: "http://localhost:5000" diff --git a/example/mai.nginx b/example/mai.nginx new file mode 100644 index 0000000..8df6a4d --- /dev/null +++ b/example/mai.nginx @@ -0,0 +1,23 @@ +server { + listen 80; + listen [::]:80; + server_name mai.example.com; + + location / { + return 301 https://$host$request_uri; + } +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name mai.example.com; + + ssl_certificate /path/to/fullchain.pem; + ssl_certificate_key /path/to/privkey.pem; + + location / { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass http://localhost:5000; + } +} diff --git a/views/429.html b/views/429.html new file mode 100644 index 0000000..b1d4f9d --- /dev/null +++ b/views/429.html @@ -0,0 +1,21 @@ + + + + + Too many requests + + + + + + + +

You have triggered a 429 error

+

Try again later

+ + + [image source] + +
+ +