????Nginx?????????nginx.conf??????????£?
????user nginx nginx ;
????Nginx??????飺??? ?顣window?2????
????worker_processes 8;
??????????????????????????????????????CPU????????2????CPU??
????error_log  logs/error.log;
????error_log  logs/error.log  notice;
????error_log  logs/error.log  info;
????????????????·????
????pid logs/nginx.pid;
????pid?????????????????·????
????worker_rlimit_nofile 204800;
???????????????????????????????
??????????????????nginx?????????????????????????????????????????ulimit -n????nginx???????????????nginx???????????????????????????ulimit -n ???????????
??????????Linux 2.6????????????????65535??worker_rlimit_nofile????????д65535??
???????????nginx???????????????????????????????????????д10240???????????3-4????н?????????10240??????????502????
????events
????{
????use epoll;
???????epoll??I/O ????linux????epoll??FreeBSD???????kqueue??window?2??????
???????????:
??????apache????nginx???????????????в??????????
????A???????????
????Select??poll??????????????????????????????Ч???????nginx?????select??poll
????B????Ч??????
????Kqueue???????FreeBSD 4.1+?? OpenBSD 2.9+?? NetBSD 2.0 ?? MacOS X.????????????MacOS X?????kqueue????????????????
????Epoll???????Linux???2.6?汾??????????
????/dev/poll???????Solaris 7 11/99+??HP/UX 11.22+ (eventport)??IRIX 6.5.15+ ?? Tru64 UNIX 5.1A+??
????Eventport???????Solaris 10?? ????????????????????? ?б??????????????
????worker_connections 204800;
????????????????????????????????????????????湤????????????????????????????cpu????С??????????????????????????????nginx??????????????????worker_processes*worker_connections
????keepalive_timeout 60;
????keepalive??????
????client_header_buffer_size 4k;
?????????????????????????С??????????????????????С?????????????????????С??????1k?????????????????????????1k????????????????????С??
?????????С??????????getconf PAGESIZE ??á?
????[root@web001 ~]# getconf PAGESIZE
????4096
?????????client_header_buffer_size????4k???????????client_header_buffer_size????????????“???????С”??????????
????open_file_cache max=65535 inactive=60s;
?????????????????????棬??????????????max??????????????????????????£?inactive?????????????????????????????檔
????open_file_cache_valid 80s;
???????????????????λ??????Ч?????
????open_file_cache_min_uses 1;
????open_file_cache????е?inactive??????????????????????????????????????????????????????????д?????????????????????????inactive??????????????????????????
????}
????##?趨http?????????????????????????????????????
????http
????{
????include mime.types;
?????趨mime???????????mime.type???????
????default_type application/octet-stream;
????log_format main '$remote_addr - $remote_user [$time_local] "$request" '
????'$status $body_bytes_sent "$http_referer" '
????'"$http_user_agent" "$http_x_forwarded_for"';
????log_format log404 '$status [$time_local] $remote_addr $host$request_uri $sent_http_location';
?????????????á?
????$remote_addr??$http_x_forwarded_for????????????ip?????
????$remote_user??????????????????????
????$time_local?? ?????????????????????
????$request?? ????????????url??httpЭ?飻
????$status?? ????????????????????200??
????$body_bytes_sent ???????????????????????????С??
????$http_referer??????????????????????????????
????$http_user_agent???????????????????????
???????web???????????????????棬?????????????????IP?????????$remote_add?????IP??????????????????iP???????????????????????????http?????У?????????x_forwarded_for?????????????п?????IP?????????????????????????????
????access_log  logs/host.access.log  main;
????access_log  logs/host.access.404.log  log404;
????????log_format???????????????????????access_log????????????????·????
????server_names_hash_bucket_size 128;
????#??????????????hash?????????server_names_hash_max_size ??server_names_hash_bucket_size????????????hash bucket size???????hash????С?????????·???????????С????????????????????е??????????????????м??????hash???????????????hash bucket size?????·????????????С???????????????????????????????в????????2?????????????洢??????????????????洢????в???? ??????????Nginx???????????hash max size ?? hash bucket size????????????????????????????????С.
????client_header_buffer_size 4k;
?????????????????????????С??????????????????????С???????????????????????С??????1k?????????????????????????1k????????????????????С???????С??????????getconf PAGESIZE??á?
????large_client_header_buffers 8 128k;
?????????????????С??nginx??????client_header_buffer_size???buffer?????header??????
????header???????????large_client_header_buffers???????
????open_file_cache max=102400 inactive=20s;
???????????????????????á?
??????: open_file_cache max=1000 inactive=20s;
????open_file_cache_valid 30s;
????open_file_cache_min_uses 2;
????open_file_cache_errors on;
????open_file_cache_errors
??????:open_file_cache_errors on | off ????:open_file_cache_errors off ??????:http?? server?? location ????????????????????????????cache????.
????open_file_cache_min_uses
??????:open_file_cache_min_uses number ????:open_file_cache_min_uses 1 ??????:http?? server?? location ?????????????open_file_cache?????Ч???????????????Χ?????????С???????????????????????????????cache?????????.
????open_file_cache_valid
??????:open_file_cache_valid time ????:open_file_cache_valid 60 ??????:http?? server?? location ???????????????????open_file_cache?л??????????Ч???.
????client_max_body_size 300m;
?????趨???nginx?????????С
????sendfile on;
????sendfile?????? nginx ??????sendfile ??????zero copy ?????????????????????????????????on????????????????????????IO????????????????off????????????????IO??????????????uptime??
????tcp_nopush on;
???????????????????socke??TCP_CORK????????????????sendfile????????
????proxy_connect_timeout 90;
??????????????????????_???????????????????
????proxy_read_timeout 180;
????????????_????????????????_??????????????????е????????????????????????????????
????proxy_send_timeout 180;
?????????????????????_????漲??????????????????????е?????
????proxy_buffer_size 256k;
?????????????????????????????????????????С??????????????????а??????С???????????????????????С????proxy_buffers???????????????????С????????????????????С
????proxy_buffers 4 256k;
??????????????????????????????????????????????С???????????????С?????????????????????4k????8k
????proxy_busy_buffers_size 256k;
????proxy_temp_file_write_size 256k;
??????????д??proxy_temp_path???????С????????????????????????????????
????proxy_temp_path /data0/proxy_temp_dir;
????proxy_temp_path??proxy_cache_path?????·??????????????
????proxy_cache_path /data0/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
????#??????滺?????С?200MB??1????б???????????????????????????С?30GB??
????keepalive_timeout 120;
????keepalive??????
????tcp_nodelay on;
????client_body_buffer_size 512k;
??????????????????????????????256k??????????????firefox????IE???????????????С??256k?????????????????????????????????client_body_buffer_size?????????????????С????????8k????16k????????????
???????????firefox4.0????IE8.0???????????200k???????????????500 Internal Server Error????
????proxy_intercept_errors on;
????????nginx???HTTP???????400???????????
????upstream bakend {
????server 127.0.0.1:8027;
????server 127.0.0.1:8028;
????server 127.0.0.1:8029;
????hash $request_uri;
????}
????nginx??upstream?????4?????????
????1???????????
?????????????????????????????????????????????????down?????????????
????2??weight
???????????????weight???????????????????????????????????????
???????磺
????upstream bakend {
????server 192.168.0.14 weight=10;
????server 192.168.0.15 weight=10;
????}
????2??ip_hash
???????????????ip??hash??????????????????????????????????????????session??????
???????磺
????upstream bakend {
????ip_hash;
????server 192.168.0.14:88;
????server 192.168.0.15:80;
????}
????3??fair??????????
???????????????????????????????????????????????
????upstream backend {
????server server1;
????server server2;
????fair;
????}