Limit connections and redirect www to canonical

Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
Egor Savkin 2024-08-15 13:09:00 +08:00
parent 2340919bb5
commit 5e64abf31c
3 changed files with 75 additions and 17 deletions

View File

@ -3,10 +3,12 @@ upstream rfq_server {
} }
server { server {
limit_conn addr 5;
root /var/www/m-labs-intl.com/html; root /var/www/m-labs-intl.com/html;
index index.html index.htm index.nginx-debian.html; index index.html index.htm index.nginx-debian.html;
server_name m-labs-intl.com www.m-labs-intl.com; server_name m-labs-intl.com;
location / { location / {
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
@ -20,8 +22,22 @@ server {
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
} }
server {
server_name www.m-labs-intl.com;
return 301 https://m-labs-intl.com$request_uri;
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/m-labs-intl.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/m-labs-intl.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server { server {
server_name hooks.m-labs-intl.com; server_name hooks.m-labs-intl.com;
limit_conn addr 1;
limit_req zone=rfq;
location /rfq { location /rfq {
proxy_pass http://rfq_server/rfq; proxy_pass http://rfq_server/rfq;
@ -35,9 +51,10 @@ server {
} }
location / { location / {
return 404; return 418;
} }
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/m-labs-intl.com/fullchain.pem; # managed by Certbot ssl_certificate /etc/letsencrypt/live/m-labs-intl.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/m-labs-intl.com/privkey.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/m-labs-intl.com/privkey.pem; # managed by Certbot
@ -46,15 +63,20 @@ server {
} }
server { server {
if ($host = www.m-labs-intl.com) { limit_conn addr 1;
if ($host = m-labs-intl.com) {
return 301 https://$host$request_uri; return 301 https://$host$request_uri;
} # managed by Certbot } # managed by Certbot
if ($host = www.m-labs-intl.com) {
return 301 https://m-labs-intl.com$request_uri;
} # managed by Certbot
listen 80; listen 80;
listen [::]:80; listen [::]:80;
server_name m-labs-intl.com www.m-labs-intl.com; server_name m-labs-intl.com www.m-labs-intl.com hooks.m-labs-intl.com;
return 301 https://$host$request_uri; return 301 https://$host$request_uri;
#return 404; # managed by Certbot
} }

View File

@ -33,6 +33,10 @@ http {
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;
# Rate limiting
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_req_zone $binary_remote_addr zone=rfq:10m rate=5r/m;
## ##
# Logging Settings # Logging Settings
## ##
@ -59,3 +63,32 @@ http {
include /etc/nginx/conf.d/*.conf; include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-enabled/*;
} }
stream {
limit_conn_zone $binary_remote_addr zone=mail:10m;
# Upstream mail servers
upstream smtp_backend {
server mail.m-labs.hk:25;
}
upstream submission_backend {
server mail.m-labs.hk:587;
}
# SMTP
server {
listen 25;
proxy_pass smtp_backend;
proxy_protocol on;
limit_conn mail 5;
}
# Submission (Authenticated SMTP)
server {
listen 587;
proxy_pass submission_backend;
proxy_protocol on;
limit_conn mail 5;
}
}

View File

@ -1,7 +1,7 @@
# Setup m-labs-intl.com server # Setup m-labs-intl.com server
```shell ```shell
apt install git nginx-full python3 python3.12-venv python3-pip postfix opendkim opendkim-tools apt install git nginx-full python3 python3.12-venv python3-pip
snap install --classic certbot snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot ln -s /snap/bin/certbot /usr/bin/certbot
useradd -m rfqserver useradd -m rfqserver
@ -51,14 +51,17 @@ certbot --nginx
service nginx restart service nginx restart
cp main.cf /etc/postfix/main.cf ufw default deny
cp virtual /etc/postfix/virtual ufw allow from 94.190.212.123
postmap /etc/postfix/virtual ufw allow from 2001:470:f891:1:5999:5529:5d:f71d
ufw allow from 202.77.7.238
cp opendkim /etc/default/opendkim ufw allow from 2001:470:18:390::2
cp opendkim.conf /etc/opendkim.conf ufw allow "Nginx HTTP"
opendkim-genkey -t -s mail -d m-labs-intl.com ufw allow "Nginx HTTPS"
cp mail.private /etc/postfix/dkim.key ufw limit OpenSSH
service opendkim restart ufw default allow outgoing
service postfix restart ufw limit 25/tcp
ufw limit 587/tcp
ufw show added
ufw enable
``` ```