Nginx 的基本配置

配置文件在哪里呢?

zhongwei@ubuntu:/var/log/nginx$ which nginx
/usr/sbin/nginx
zhongwei@ubuntu:/var/log/nginx$ /usr/sbin/nginx -V
nginx version: nginx/0.7.67
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-0.7.67/modules/nginx-upstream-fair
zhongwei@ubuntu:/var/log/nginx$ 

通过 nginx -V 可以清楚的看到 nginx.conf 位于 /etc/nginx 下。

Nginx 的进程体系结构:

Nginx 有两种进程: a. Master process; b. Worker process.

启动 Nginx 时只有一个进程,即 master process. Master process 并不处理客户端的请求, 而是一批 worker processes 来处理。在配置文件中, 可以设置 worker process 的数量, 以及每个 worker process 可以处理的最大连接数。

按照 CPU core 的数量来决定 worker process 的个数。例如, 如果有一个 4核的 CPU, 那么就应该将 worker processes 设置为 4.

而 work_connections 的大小取决于内存的大小和 CPU 的处理能力, 主要取决于 RAM 的大小。

worker_processes 和 worker_connections 的设置对性能起着决定性的影响。如果 work_processes 不等于 CPU core 的数量, 会造成部分核未使用或者未充分利用, 部分核效率低下。若 worker_connections 设置过低, 或造成连接被拒绝; 过高,会造成内存泄漏或者系统崩溃。不幸的是, 没有一个简单的方法来估算 worker_connections 的值, 通常根据流量来估值。

性能测试:

避免将测试工具和 Nginx 放在同一台机器上, 测试结果会不准确。

常用的测试工具: httperf, Autobench, OpenWebLoad. 原理是, 产生大量的 HTTP 请求试图"搞跨" server, 对结果生成分析报告。

Autobench 是对 httperf 的一个扩展, 报告数据可以方便的生成图表, 可以显示成功的请求量和失败的请求量。

优雅的升级:

Ngnix 支持在不丢失请求的情况下升级。

猜你喜欢

转载自zhongwei-leg.iteye.com/blog/807979