limit_req_zone $binary_remote_addr zone=mapas:10m rate=5r/s;

# Se estiver atrás de um proxy ou load balancer
# limit_req_zone $http_x_forwarded_for zone=mapas:10m rate=5r/s;

# Referência de como configurar uma allow list de ip's que nao serão restringidos.
# https://serverfault.com/questions/177461/how-to-rate-limit-in-nginx-but-including-excluding-certain-ip-addresses


server {
    listen 80;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
    
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    client_max_body_size 1G;

    root /var/www/html;

    location / {
        index index.php index.html;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff)$ {
        expires 1w;
        log_not_found off;
    }

    location ~ /index\.php$ {
        limit_req zone=mapas burst=20 nodelay;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass mapasculturais:9000;
        fastcgi_index index.php;
        fastcgi_read_timeout 3600;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ .*\.php$ {
        deny all;
        return 403;
    }

    charset utf-8;
}