Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limit req to nginx conf to prevent DDOS #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion nginx/nginx.conf.prod.template
atxr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ http {
include mime.types;
default_type application/octet-stream;

# Avoid DDOS
limit_req_zone ${DOLLAR}binary_remote_addr zone=one:10m rate=5r/s;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
Expand All @@ -35,34 +38,39 @@ http {
server_tokens off;

location /.well-known/acme-challenge/ {
limit_req zone=one burst=20;
root /var/www/certbot;
}

location / {
limit_req zone=one burst=20;
return 301 https://${SERVER_NAME}${DOLLAR}request_uri;
}
}

server {
listen 443 default_server ssl http2;
listen [::]:443 ssl http2;

server_name $SERVER_NAME www.${SERVER_NAME};

ssl_certificate /etc/nginx/ssl/live/${SERVER_NAME}/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/${SERVER_NAME}/privkey.pem;

location / {
limit_req zone=one burst=20;
proxy_pass http://react-app:$REACT_PORT;
}

location /api {
limit_req zone=one burst=20;
proxy_pass http://node-app:$NODE_PORT;
}

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
limit_req zone=one burst=20;
root /usr/share/nginx/html;
}

Expand Down