参考资料

  1. NginxPython(Django)项目部署详细说明以及案例
  2. nginx 配置域名
  3. 如何通过响应头防御XSS?
  4. Nginx如何支持高并发?
  5. NginxWebDAV模块配置详细说明以及案例
  6. Nginx伪流媒体服务器搭建详细说明以及案例
  7. Nginx代理缓存配置详细说明以及案例
  8. nginx是否需要开启HTTP/2支持以提高安全性?
  1. 反向代理

  • 参数:proxy_pass

  • 示例:

location / {
    proxy_pass http://backend_server;
}
  1. 负载均衡

  • 参数:upstream

  • 示例:

upstream backend {
    server 192.168.1.100:8080;
    server 192.168.1.101:8080;
}
  1. 静态文件服务

  • 参数:root, index

  • 示例:

server {
    root /var/www/html;
    index index.html;
}
  1. SSL/TLS加密

  • 参数:ssl_certificate, ssl_certificate_key

  • 示例:

server {
    listen 443 ssl;
    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;
}
  1. 虚拟主机

  • 参数:server_name

  • 示例:

server {
    listen 80;
    server_name example.com;
}
  1. URL重写

  • 参数:rewrite

  • 示例:

rewrite ^/old/(.*)$ /new/$1 permanent;
  1. 访问控制

  • 参数:allow, deny

  • 示例:

location /admin {
    allow 192.168.1.0/24;
    deny all;
}
  1. Gzip压缩

  • 参数:gzip

  • 示例:

gzip on;
gzip_types text/plain text/css application/json;
  1. 缓存控制

  • 参数:proxy_cache_path, proxy_cache

  • 示例:

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m;
location / {
    proxy_cache my_cache;
}
  1. 日志记录

  • 参数:access_log, error_log

  • 示例:

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;