极简工具箱

免费在线工具 · 本地计算 · 无需上传

Nginx 配置模板

常用 Nginx 配置片段,复制即用,按需拼接。

广告位(百度联盟文中广告位)
静态站点 server 块
server {
    listen 80;
    server_name it586.cn;
    root /var/www/html;
    index index.html;
    location / { try_files $uri $uri/ /index.html; }
}
反向代理
location /api/ {
    proxy_pass http://127.0.0.1:8080/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}
HTTPS (SSL)
listen 443 ssl;
ssl_certificate     /path/fullchain.pem;
ssl_certificate_key /path/privkey.pem;
Gzip 压缩
gzip on;
gzip_types text/css application/javascript image/svg+xml;
静态缓存
location ~* \.(js|css|png)$ {
    expires 30d;
    add_header Cache-Control "public";
}
限流
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
location / { limit_req zone=one burst=20; }
广告位(百度联盟信息流广告位)
广告位(百度联盟底部横幅)