インストール手順の更新、例の追加、リミッターの再構成

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/mai/trunk@68 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
This commit is contained in:
yakumo.izuru 2024-02-11 00:56:18 +00:00
parent b860f0610b
commit f1d0667b80
5 changed files with 73 additions and 4 deletions

View File

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

View File

@ -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")

16
example/mai.h2o.yml Normal file
View File

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

23
example/mai.nginx Normal file
View File

@ -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;
}
}

21
views/429.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="/static/style.css">
<title>Too many requests</title>
</head>
<body>
<table border="1" align="center">
<thead>
<img src="/static/displeased_mai.png">
</thead>
<tbody>
<p>You have triggered a 429 error</p>
<p>Try again later</p>
</tbody>
<tfoot>
<i><a href="https://deviantart.com/view/1017571065">[image source]</a></i>
</tfoot>
</table>
</body>
</html>