This commit is contained in:
2026-11-28 11:21:08 -05:00
parent df4861cba6
commit 2d3ee73186
4 changed files with 170 additions and 12 deletions

70
nginx.conf Normal file
View File

@ -0,0 +1,70 @@
## This file is included inside nginx's http block (e.g. from sites-enabled),
## so the limit_req_zone and map directives below are valid here.
## Rate limiting (ngx_http_limit_req_module: built into nginx by default).
## The zones key on the client IP. If nginx sits behind another proxy or
## load balancer, every request appears to come from that proxy's IP and
## all clients share one limit. In that case, uncomment the real_ip lines
## in the server block below.
## General limit for every request, including short-link redirects.
limit_req_zone $binary_remote_addr zone=shortener_all:10m rate=10r/s;
## Stricter limit for requests that can create a link or try a password:
## any POST, or a GET carrying ?url= or ?password=. Plain GET/HEAD requests
## get an empty key, which nginx doesn't count against this zone.
map "$request_method:$arg_url$arg_password" $shortener_write_key {
"~^(GET|HEAD):$" "";
default $binary_remote_addr;
}
limit_req_zone $shortener_write_key zone=shortener_write:10m rate=10r/m;
server {
listen 3337;
## Your website name goes here.
server_name r.bagaag.com;
## Your only path reference.
root /var/www/shortener;
## Behind a proxy: trust its X-Forwarded-For header so rate limits apply
## per real client (needs ngx_http_realip_module, which distro packages
## include). Set the proxy's address.
# set_real_ip_from 127.0.0.1;
# real_ip_header X-Forwarded-For;
limit_req_status 429;
port_in_redirect off;
## Browsers ask for this automatically; answer quietly without logging.
location = /favicon.ico {
log_not_found off;
access_log off;
return 404;
}
## The one static file served: tells crawlers to stay out.
location = /robots.txt {
access_log off;
try_files /robots.txt =404;
}
## Every other path is handled by index.php, so nothing else in the
## directory (urls.txt, last.txt, .git, README.md, nginx.conf, ...) is
## ever served directly. The original URI is preserved in REQUEST_URI,
## which index.php uses to look up short-link keys.
location / {
rewrite ^ /index.php last;
}
location = /index.php {
limit_req zone=shortener_all burst=20 nodelay;
limit_req zone=shortener_write burst=5 nodelay;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
proxy_set_header Host r.bagaag.com;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
client_max_body_size 1M;
}
}