nginx

Nginx :,

Syntax

Parameters

ParametersDescriptionExamplesLevel
server_tokens off Nginx server_tokens off; Common
add_header X-Frame-Options add_header X-Frame-Options SAMEORIGIN; Common
add_header X-Content-Type-Options MIME add_header X-Content-Type-Options nosniff; Common
limit_req_zone limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; Common
client_max_body_size client_max_body_size 10m; Common

Examples

server {
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header Referrer-Policy strict-origin-when-cross-origin;
    server_tokens off;
}
,

API

http {
    limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
}
server {
    location /api/ {
        limit_req zone=api burst=20 nodelay;
    }
}
IP 10, 20

location ~ /\.(git|env|htaccess) {
    deny all;
    return 404;
}
location ~ \.(sql|bak|log)$ {
    deny all;
}
, and

IP

location /admin/ {
    allow 192.168.1.0/24;
    allow 10.0.0.1;
    deny all;
}

Common Errors

limit_reqburst rate, nodelay

Tips

Related Commands