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 @@ + + +
+ +