Nginx笔记-03-常用配置

Nginx配置

nginx.conf配置文件有三大块:全局快、events块、http块

全局块

在这里插入图片描述

指令名	指令值;  #全局块,主要设置Nginx服务器整体运行的配置指令
指令名指令值默认值作用
user用户nobody指定访问文件夹(静态文件)的用户,若无权限则403
master_processeson/offon指定是否开启工作进程
*worker_processes数值1配置nginx并发数,建议与cpu内核数一致或更低
daemonon/offon是否后台执行nginx
pid路径…/nginx.pid存储pid的文件路径
error_log路径…/error.log存储错误日志路径
includexx.conf引入其他配置

events块

在这里插入图片描述

#events块,主要设置,Nginx服务器与用户的网络连接,这一部分对Nginx服务器的性能影响较大
events {	 
    指令名	指令值;
}
指令指令值默认值作用
accept_mutexon/offon网络连接序列化
*multi_accepton/offoff是否运行同时收到多个网络连接,建议设置on
*worker_connections数值512单个worker最大连接数
*useselect/poll/epoll/kqueue根据操作系统而定nginx底层使用的函数.在linux2.6以上默认使用epoll

http块

在这里插入图片描述

#http块,是Nginx服务器配置中的重要部分,代理、缓存、日志记录、第三方模块配置...             
http {		
    指令名	指令值;
    #server块,是Nginx配置和虚拟主机相关的内容
    server {
    	#location块,基于Nginx服务器接收请求字符串与location后面的		值进行匹配,对特定请求进行处理
    	指令名	指令值;
    	location uri { 
    		指令名	指令值;
        	...
        }
        ...
    }
	...
}
指令指令值默认值作用块作用
*include导入外部配置http通常会在http块中导入mime.type,这是用来解析前端响应的资源,使用default必须导入mime.type
*default_type资源类型如:application/json、application/octet-stream(二级制文件)text/plainhttp/server/location设置响应的资源类型
access_loglog路径 格式名(不填则默认)logs/access.log combinedhttp/server/location设置log输出路径
log_format格式名 格式combined “…”http格式化log输出样式
*sendfileon/offoffhttp/server/location是否使用sendfile()函数提升文件传输性能,建议设置为on
*tcp_nopuson/offoffhttp/server/locationsendfile打开的状态下才会生效,提高网络传输效率,建议设置为on
*tcp_nodelayon/offoffhttp/server/location有网的的情况下才生效,保证网络连接实效性,建议设置为on
*keepalive_timeout数值75shttp/server/locationhttp长连接超时时间
keepalive_requests数值100http/server/location一个长连接最多被使用次数
*listen数值80server监听端口
*server_nameip/域名localhostserver监听的IP/域名
*root资源目录location静态资源所对应的目录
alias资源目录location同root
*index静态资源location访问uri默认打开的静态资源
*error_page状态码 uriserver当出现该状态码时,响应某location的uri
*gizpon/offoffhttp/server/location打开压缩模块,建议设置为on
*gzip_types资源类型如:application/jsontext/htmlhttp/server/location指定压缩文件类型
*gzip_comp_level1-91http/server/location压缩强度,1最低,9最高,建议设置为5或6
*gzip_varyon/offoffhttp/server/location被压缩文件是否带“Vary:Accept-Encoding”的响应头,建议设置为on
gzip_buffers空间数 大小32 4khttp/server/location压缩申请的空间数和大小
*gzip_disable正则表达式http/server/location“User-Agent"请求头匹配正则表达式,则不压缩,建议设置为"MSIE [1-6].”,对IE6以下浏览器禁用压缩
gzip_http_version1.0/1.11.1http/server/location针对不同HTTP协议版本选择性地开启Gzip功能
*gzip_min_length数据大小20http/server/location超过指定数据大小则不压缩,建议设置为1k
*gzip_proxiedoff/any/请求头信息offhttp/server/location建议设置为expired no-cache no-store private auth
*gzip_staticon/offoffhttp/server/location避免gzip和sendfile,建设置为on
*add_header响应头信息http/server/location设置响应头信息
*expirestime/off/maxoffhttp/server/location设置缓存时间(add_header也可以设置)
valid_referersnone/blocked/server_names/正则表达式server/location设置防盗链
*proxy_passurllocation设置被代理服务器地址
*proxy_set_header请求头 信息location代理时,更改/添加请求头信息
proxy_redirect被代理IP 代理IP/default/offdefaultlocation代理时,更改请求头Refer和响应头Location为代理IP
ssloffon/offhttp、server启HTTPS,可以使用 listen 443 ssl
ssl_certificate路径http、serverPEM格式证书
ssl_certificate_key路径http、server证书Key
ssl_session_cacheoff/none/builtin/sharednonehttp、serverSSL会话缓存
ssl_session_timeout时间5mhttp、server缓存中的会话参数时间
ssl_ciphers密码格式HIGH:!aNULL:!MD5http、server指出允许的密码
ssl_prefer_server_cipherson/offoffhttp、server指定是否服务器密码优先客户端密码
proxy_cache_path路径 属性http设置Nginx本地缓存路径
proxy_cachename/offoffhttp/server/location指定Nginx本地缓存名字
proxy_cache_key s c h e m e scheme schemeproxy_host$request_urihttp/server/location设置Nginx缓存文件名使用的是什么值的MD5
proxy_cache_valid状态码 时间http/server/location设置Nginx缓存状态码和状态码缓存时间
proxy_cache_min_uses数值1http/server/location设置资源被访问多少次后被缓存
proxy_cache_methods请求方法GEThttp/server/location设置缓存哪些HTTP方法
proxy_cache_purgename keyhttp/server/location清除缓存
proxy_no_cache条件http/server/location符合条件不缓存
proxy_cache_bypass条件http/server/location符合条件不从缓存中获取数据
*proxy_buffers数量 文件大小256 8khttp/server/location响应体初始大小,当不够时会再申请,建议调小
*proxy_buffer_size文件大小4k/8khttp/server/location响应头初始大小,当不够时会再申请,建议调小
*proxy_busy_buffer_size文件大小http/server/locationnginx会在没有完全读完后端响应就开始向客户端传送数据,所以它会划出一部分busy状态的buffer来专门向客户端传送数据
autoindex offon/offoffhttp/server/location启用或禁用目录列表输出
autoindex_exact_sizeon/offonhttp/server/location显示目录文件的具体大小
autoindex_formathtml/json/xmlhtmlhttp/server/location目录显示格式
autoindex_localtimeon/offoffhttp/server/location显示当前时间
auth_basicon/offoffhttp/server/location开启用户认证
auth_basic_user_file路径http/server/location指定用户名和密码所在文件
*charset编码http/server/location指定编码,建议设置utf-8
lua_package_path路径“user/local/openrestry/lualib/?.lua;;”http导入第三方lua模块
lua_package_cpath路径“user/local/openrestry/lualib/?.so;;”http导入c模块
*server_names_hash_bucket_size数据大小http服务器名大小限制
*client_header_buffer_size数据大小http请求头大小限制
*large_client_header_buffers个数 数据大小http请求行+请求头限制个数*大小
*client_max_body_size数据大小http最大上传文件
limit_conn_zone参数 zone=名字:带宽http限制参数的并发连接数以及带宽,名字可随便取,不重复就行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值