nginx配置学习
user nginx nginx;
worker_process 4;//cpu core
error_log logs/error.log notice;//debug info warn error crit
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;//linux 下用epoll 。unix系統下一班用kquque ,原因不知
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format nginx '$remote_addr - $remote_user [$time_local] "$request" '
??? ??? ??? ??? '$status $body_bytes_sent "$http_referer" '
??? ??? ??? ??? ' "$http_user_agent" "$http_x_forwarded_for" ';
access_log logs/access.log nginx;
###########
client_max_body_size 20m;//請求頭字段中指定的客戶端請求主體,設置允許的最大大小。如果超過設定的值,客戶端錯誤413(請求實體過大),則返回
client_header_buffer_size 32k;//指令設置headerbuffer的來自客戶端的請求標頭的大小。
client_body_temp_path /data/nginx/temp 1 2;
server_names_hash_bucket_size 128;//name server 的長度設置
large_client_header_buffers 4 32k;
#請求行不能大于一個緩沖區的大小,如果客戶端發送一個更大的頭nginx的返回錯誤“請求URI過大”(414)。
#最長的標題行的要求也必須是不超過一個緩沖區的大小,否則客戶端將得到錯誤“錯誤的請求”(400)。
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 60;
#
client_body_buffer_size? 512k;#緩沖去代理用戶請求的最大字節數,可以理解為先保存本地,然后在傳給用戶
proxy_connect_timeout??? 60;? #代理連接超時時間 官方建議不要超過75秒 默認為60秒
proxy_read_timeout?????? 60;? #從代理服務器讀取回復的超時時間
proxy_send_timeout?????? 60;? #發送到代理服務器的超時時間
proxy_buffer_size??????? 16k; #代理的buffer大小用戶緩存代理回復的header 其大小由proxy_buffers指令指定
proxy_buffers??????????? 4 64k;?
proxy_busy_buffers_size 128k;? #高負載下緩沖大小
proxy_temp_file_write_size 128k; //proxy緩存臨時文件的大小
#
gzip on;?
gzip_min_length? 1k;?
gzip_buffers???? 4 16k;?
gzip_http_version 1.1;?
gzip_comp_level 2;?
gzip_types?????? text/plain application/x-javascript text/css application/xml;?
gzip_vary on;
proxy_temp_path?? /data/proxy_temp_dir;?
? #設置Web緩存區名稱為cache_one,內存緩存空間大小為200MB,1天沒有被訪問的內容自動清除,硬盤緩存空間大小為30GB。?
proxy_cache_path? /data/proxy_cache_dir? levels=1:2?? keys_zone=cache_one:200m inactive=1d max_size=30g;
#Starting from version 0.8.9 temporary files and the cache can be put on different file systems but be aware that in this case a file #is copied across two file systems instead of the cheap rename operation. It is thus recommended that for any given location both #cache and a directory holding temporary files set by the proxy_temp_path directive are put on the same file system.
upstream backend_server {?
??? server?? 192.168.0.251:80 weight=1 max_fails=2 fail_timeout=30s;? 定義server的地址和端口 以及權重 和最大失敗次數和失敗的超時時間
??? server?? 192.168.0.252:80 weight=1 max_fails=2 fail_timeout=30s;?
??? server?? 192.168.0.253:80 weight=1 max_fails=2 fail_timeout=30s;?
? } upstream 中的參數
?
#iphash
#keepalive connections
######
server?
{?
??? listen?????? 80;?
??? server_name? 192.168.0.20;?
??? index index.html index.htm;?
??? root? /data/htdocs/www;???
?
??? location /?
??? {?
???????? #如果后端的服務器返回502、504、執行超時等錯誤,自動將請求轉發到upstream負載均衡池中的另一臺服務器,實現故障轉移。?
???????? proxy_next_upstream http_502 http_504 error timeout invalid_header;?
???????? proxy_cache cache_one;?
???????? #對不同的HTTP狀態碼設置不同的緩存時間?
???????? proxy_cache_valid? 200 304 12h;?
???????? #以域名、URI、參數組合成Web緩存的Key值,Nginx根據Key值哈希,存儲緩存內容到二級緩存目錄內?
???????? proxy_cache_key $host$uri$is_args$args;?
???????? proxy_set_header Host? $host;?
???????? proxy_set_header X-Forwarded-For? $remote_addr;?
???????? proxy_pass http://backend_server;?
???????? expires????? 1d;?
??? }?
??? location ~ /purge(/.*)
??? {
- auth_basic “Please Insert User And Password”;
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;//http://labs.frickle.com/nginx_ngx_cache_purge/README
??? }
}
####
..........
深入的學習nginx,博客當做是自己學習的記錄。。。發上來和各位分享。。
?
轉載于:https://blog.51cto.com/zxhforlinux/1159961
總結
- 上一篇: 文件的上传下载(一)
- 下一篇: 12款免费素材图标系列三