Tengine(二) 之 nginx.conf

来源:互联网 发布:深圳微软软件代理商 编辑:程序博客网 时间:2024/06/03 15:48

nginx.conf是配置tengine的最重要的文件,掌握了配置nginx.conf也就能很轻松驾驭tengine了.

一. 一个”hello world”的nginx配置:

#user  nobody;worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  75;    server {        listen       80;        server_name  localhost;        location / {            root   html;            index  index.html index.htm;        }    }}

tengine是多进程的,下图显示了nginx当前的两个进程,一个进程是root的用于管理,另外的进程权限是任何人,用于服务.
这里写图片描述
1.worker_processes配置tengine的用于服务的进程数,建议配置和CPU数量相同的进程数.也可以配置为auto,即自动配置,原理也是根据CPU数量来配置.
2.worker_connections配置每个进程的并发最大线程数量,经过大量测试,官方建议配置1024个.
3.keepalive设置连接时间,官方建议75秒,设置策略,可以参考博客http://blog.csdn.net/super_scan/article/details/41451203
————————————————————————————————————————————
重点来了:
4.nginx可以配置很多台虚拟主机server,一个server表示一台机器服务.
比如:

server {        listen       80;        server_name  www.fly.com;        location / {            root   html;            index  index.html index.htm;        }    }

listen监听端口号
server_name虚拟主机名
location转发地址

这台server的作用是:
客户机访问nginx服务器时,如果访问域名匹配www.fly.com且端口为80,这台server将会把信息交给对应的location处理

5.location才是重点

location / {            root   html;            index  index.html index.htm;        }

root 请求的目录,root这个词没用好,但官方文档解释得很详细
http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#root
index 请求的文件

二. 一个简单的nginx.conf配置
还是官方API讲得好
http://tengine.taobao.org/nginx_docs/cn/docs/http/request_processing.html

0 0