nginx
Nginx :, and
Syntax
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
sendfile |
sendfile on; |
Common | |
tcp_nopush |
tcp_nopush on; |
Common | |
keepalive_timeout |
keepalive_timeout 65; |
Common | |
gzip |
gzip on; |
Common | |
proxy_cache |
proxy_cache my_cache; |
Advanced | |
open_file_cache |
open_file_cache max=1000 inactive=20s; |
Advanced |
Examples
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# Gzip
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript text/xml;
}http {
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m;
}
server {
location /api/ {
proxy_cache my_cache;
proxy_cache_valid 200 10m;
proxy_cache_valid 404 1m;
proxy_pass http://backend;
}
},
Worker
worker_processes auto;
worker_rlimit_nofile 65535;
events {
worker_connections 4096;
multi_accept on;
use epoll;
}Common Errors
worker_connections are not enoughworker_connections, ulimit -n
Tips
- worker_processes auto CPU
- gzip ()
- proxy_cache