目录
最近公司用到Nginx服务器,本着复习一遍,顺便写个笔记的想法,把常用参数配置总结一下:
1、模块简介
1.1 主模块
# 配置用户或者组,默认为nobody nobody。
#user www www;
#Nginx开启的worker进程数,建议为CPU的核数
#worker_processes 2;
#指定nginx进程运行文件存放地址
#pid /nginx/pid/nginx.pid;
#指定日志路径,级别。这个设置可以放入全局块、http块、server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
error_log log/error.log debug;
#可以在任意地方使用include指令实现配置文件的包含,类似于apache中的include方法,可减少主配置文件长度。
include vhosts/*.conf;
1.2 事件模块
events {
#设置网路连接序列化,防止惊群现象发生,默认为on
accept_mutex on;
#默认: 500ms 如果一个进程没有互斥锁,它将延迟至少多长时间。默认情况下,延迟是500ms 。
accept_mutex_delay 100ms;
#设置一个进程是否同时接受多个网络连接,默认为off
multi_accept on;
#事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport,不建议设置,nginx会自行选择
#use epoll;
#最大连接数,默认为512
worker_connections 1024;
}
1.3 http部分
http {
#文件扩展名与文件类型映射表
include mime.types;
# 默认文件类型,默认为text/plain
default_type application/octet-stream;
#取消服务日志
#access_log off;
#允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
sendfile on;
#每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
sendfile_max_chunk 100k;
#连接超时时间,默认为75s,可以在http,server,location块。
keepalive_timeout 65;
#开启gzip资源压缩
gzip on;
# 负载均衡,详细可看了一篇文章:https://learnku.com/articles/36737
upstream blog {
server 192.167.20.19:8081;
server 192.168.10.121:8080 weight=5;
}
#设定请求缓冲
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
#上传文件的大小限制 默认1m
client_max_body_size 8m;
server {
#单连接请求上限次数。
keepalive_requests 120;
#监听端口
listen 80;
#监听地址
server_name blog.13sai.com;
#设定日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
acces