Nginx基础参数配置优化,先上基础配置,后面段落详细描述。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
user nobody; worker_processes auto; worker_cpu_affinity auto; worker_rlimit_nofile 65536; error_log /dev/null; events { worker_connections 10240; multi_accept on; use epoll; } http { include mime.types; default_type text/html; sendfile on; keepalive_timeout 65; gzip on; server_names_hash_bucket_size 128; client_header_buffer_size 4k; large_client_header_buffers 4 32k; client_max_body_size 8m; tcp_nopush on; open_file_cache max=102400 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 1; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip_disable "MSIE [1-6]."; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 9; gzip_types image/jpeg image/gif image/png text/javascript text/plain application/x-javascript text/css application/xml; gzip_vary on; #具体SERVER配置暂时省略,后续单独讲解 } |
核心模块讲解:具体参考引用:http://nginx.org/en/docs/ngx_core_module.html
1、工作用户(user):一般新建用户或者nobody,保证服务器安全。
2、工作线程数(worker_processes):定义工作进程数。 auto:会根据系统cpu个数自动调整,方便我们在使用云机器的时候调整了内核个数,机器重启生效后,这里的参数还需要调整。
3、CPU亲核力(worker_cpu_affinity):这个参数指定的是Nginx的工作线程在那些CPU核上跑。 具体参考:http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity
4、指定要使用的连接处理(use):这个是指定nginx的工作连接处理方式,具体可以参考:http://nginx.org/en/docs/events.html
select标准方法。支持模块是在缺少更有效方法的平台上自动构建的。的--with-select_module和--without-select_module配置参数可以用来强制地启用或禁用该模块的版本。poll标准方法。支持模块是在缺少更有效方法的平台上自动构建的。的--with-poll_module和--without-poll_module配置参数可以用来强制地启用或禁用该模块的版本。kqueue在FreeBSD 4.1 +,OpenBSD 2.9 +,NetBSD 2.0和macOS上使用的有效方法。epoll在Linux 2.6+上使用的有效方法。该EPOLLRDHUP(Linux的2.6.17,glibc的2.8)和EPOLLEXCLUSIVE(4.5的Linux,glibc的2.24)标志1.11.3以来的支持。一些较旧的发行版(如SuSE 8.2)提供的修补程序可为2.4内核增加epoll支持。/dev/poll在Solaris 7 11/99 +,HP / UX 11.22+(事件端口),IRIX 6.5.15+和Tru64 UNIX 5.1A +上使用的有效方法。eventport事件端口,Solaris 10+上使用的/dev/poll方法(由于已知问题,建议改用该方法)。
Http模块优化,这里主要参考:http://nginx.org/en/docs/http/ngx_http_core_module.html
fastcgi_* :针对fastcgi进行参数优化。
gzip_* :针对内容传送开启压缩传送 参数优化。