-
#user nobody; #运行nginx的用户
-
-
worker_processes 1; #于服务器核心数相同
-
-
worker_rlimit_nofile 100000; #nginx进程打开的最多文件描述符数目,ulimit -n相同
-
-
#error_log logs/ .log; #各种日志放哪里
-
#error_log logs/ .log notice;
-
#error_log logs/ .log info;
-
-
pid logs/nginx.pid; #pid文件
-
-
-
events { #Nginx事件处理模型
-
worker_connections 10000; #单个worker进程允许客户端最大连接数
-
multi_accept on; #一次accept一个新连接,or 一次accept所有的新连接
-
use epoll; #nginx采用epoll事件模型,处理效率高
-
}
-
-
-
http {
-
include mime.types; #媒体类型,include 只是一个在当前文件中包含另一个文件内容的指令
-
-
default_type application/octet-stream;
-
-
#log_format main '$remote_addr - $remote_user [$time_local] '
-
# '$status $body_bytes_sent '
-
# ' ';
-
#access_log logs/access.log main;
-
-
server_tokens off;
-
-
error_log error.log crit;
-
-
sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。如果图片显示不正常把这个改成off。
-
-
tcp_nopush on; #必须在sendfile开启模式才有效,防止网路阻塞,积极的减少网络报文段的数量(将响应头和正文的开始部分一起发送,而不一个接一个的发送。)
-
-
tcp_nodelay on; #必须在sendfile开启模式才有效,防止网路阻塞,积极的减少网络报文段的数量(将响应头和正文的开始部分一起发送,而不一个接一个的发送。)
-
-
keepalive_timeout 60; #客户端连接保持会话超时时间,超过这个时间,服务器断开这个链接
-
-
client_header_timeout 10; #设置请求头的超时时间。我们也可以把这个设置低些,如果超过这个时间没有发送任何数据,nginx将返回request time out的错误
-
client_body_timeout 10; #设置请求体的超时时间。我们也可以把这个设置低些,超过这个时间没有发送任何数据,和上面一样的错误提示
-
-
reset_timedout_connection on; #告诉nginx关闭不响应的客户端连接。这将会释放那个客户端所占有的内存空间。
-
-
send_timeout 10; #响应客户端超时时间,这个超时时间仅限于两个活动之间的时间,如果超过这个时间,客户端没有任何活动,nginx关闭连接
-
-
-
#default_type text/html;
-
-
charset UTF-8;
-
-
-
gzip on; #开启页面压缩
-
gzip_disable "msie6";
-
gzip_proxied any;
-
gzip_min_length 1000;
-
gzip_comp_level 6;
-
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
-
-
open_file_cache max=100000 inactive=20s; #这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件
-
数一致,inactive 是指经过多长时间文件没被请求后删除缓存。
-
-
open_file_cache_valid 30s; #这个是指多长时间检查一次缓存的有效信息。
-
-
open_file_cache_min_uses 2; #open_file_cache指令中的inactive 参数时间内文件的最少使用次数,如果超过这个数字,文
-
件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive 时间内一次没被使用,它将被移除。
-
-
open_file_cache_errors off;
-
-
-
server { #主机字段
-
listen 80; #监听端口
-
server_name www.zjswdlt.cn; #域名
-
#charset koi8-r;
-
-
#access_log logs/host.access.log main;
-
-
location / {
-
root html; #页面所在目录
-
index index.html index.htm index.php; #首页文件
-
}
-
-
#error_page 404 /404.html; #404页面
-
-
# redirect server error pages to the static page /50x.html
-
#
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
-
#
-
#location ~ \.php$ {
-
# proxy_pass http://127.0.0.1;
-
#}
-
-
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
-
-
location ~ \.php$ { #打开php解析
-
root html/bbs; #php页面地址
-
fastcgi_pass 127.0.0.1:9000; #启用端口
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
-
-
# concurs with nginx's one
-
#
-
#location ~ /\.ht {
-
# deny all;
-
#}
-
}
-
-
-
# another virtual host using mix of IP-, name-, and port-based configuration
-
#
-
#server {
-
# listen 8000;
-
# listen somename:8080;
-
# server_name somename alias another.alias;
-
-
# location / {
-
# root html;
-
# index index.html index.htm;
-
# }
-
#}
-
-
-
# HTTPS server
-
#
-
#server {
-
# listen 443 ssl;
-
# server_name localhost;
-
-
# ssl_certificate cert.pem;
-
# ssl_certificate_key cert.key;
-
-
# ssl_session_cache shared:SSL:1m;
-
# ssl_session_timeout 5m;
-
-
# ssl_ciphers HIGH:!aNULL:!MD5;
-
# ssl_prefer_server_ciphers on;
-
-
# location / {
-
# root html;
-
# index index.html index.htm;
-
# }
-
#}
-
-
}
nginx配置文件详解(优化)
最新推荐文章于 2024-05-23 11:22:18 发布