1 #运行用户
2 user nobody;
3 #启动进程,通常设置成和cpu的数量相等
4 worker_processes 1;
5
6 #全局错误日志及PID文件
7 #error_log logs/error.log;
8 #error_log logs/error.log notice;
9 #error_log logs/error.log info;
10 #记录nginx的master主进程
11 #pid logs/nginx.pid;
12
13 #工作模式及连接数上限
14 events {
15 #epoll是多路复用IO(I/O Multiplexing)中的一种方式,
16 #仅用于linux2.6以上内核,可以大大提高nginx的性能
17 use epoll;
18
19 #单个后台worker process进程的最大并发链接数
20 worker_connections 1024;
21 }
22
23
24 http {
25 #设定mime类型,类型由mime.type文件定义
26 include mime.types;
27 default_type application/octet-stream;
28 #设定日志格式
29 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
30 '$status $body_bytes_sent "$http_referer" '
31 '"$http_user_agent" "$http_x_forwarded_for"';
32
33 access_log logs/access.log main;
34
35 #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
36 #对于普通应用,必须设为 on,
37 #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
38 #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
39 sendfile on;
40 #tcp_nopush on;
41
42 #连接超时时间
43 #keepalive_timeout 0;
44 keepalive_timeout 65;
45 tcp_nodelay on;
46
47 #开启gzip压缩
48 gzip on;
49 gzip_disable "MSIE [1-6].";
50
51 #设定请求缓冲
52 client_header_buffer_size 128k;
53 large_client_header_buffers 4 128k;
54
55
56 #设定虚拟主机配置
57 server {
58 #侦听80端口
59 listen 80;
60 #定义使用 www.nginx.cn访问
61 server_name www.nginx.cn;
62
63 #定义服务器的默认网站根目录位置
64 root html;
65
66 #设定本虚拟主机的访问日志
67 access_log logs/nginx.access.log main;
68
69 #默认请求
70 location / {
71
72 #定义首页索引文件的名称
73 index index.php index.html index.htm;
74
75 }
76
77 # 定义错误提示页面
78 error_page 500 502 503 504 /50x.html;
79 location = /50x.html {
80 }
81
82 #静态文件,nginx自己处理
83 location ~ ^/(images|javascript|js|css|flash|media|static)/ {
84
85 #过期30天,静态文件不怎么更新,过期可以设大一点,
86 #如果频繁更新,则可以设置得小一点。
87 expires 30d;
88 }
89
90 #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
91 location ~ .php$ {
92 fastcgi_pass 127.0.0.1:9000;
93 fastcgi_index index.php;
94 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
95 include fastcgi_params;
96 }
97
98 #禁止访问 .htxxx 文件
99 location ~ /.ht {
100 deny all;
101 }
102
103 }
104 }