Nginx的基本属性配置

发布时间:2021-06-24 14:19:03 作者:chen
来源:亿速云 阅读:86

这篇文章主要讲解了“Nginx的基本属性配置”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Nginx的基本属性配置”吧!

1. Nginx服务的基本配置

1.1 用于调试进程和定位问题的配置项
1.2 正常运行的配置项
1.3 优化性能的配置项
1.4 事件类配置项

2. http核心模块配置

2.1 监听端口
listen address:port[default(deprecated)|default_server|[backlog=num|rcvbuf=size|sndbuf=size|accept_filter=filter|deferred|bind|ipv6only=[on|off]|ssl]]
2.2 主机名称
语法:server_name name [...];
默认:server_name "";
配置块:server
2.3 server_names_hash_bucket_size
语法:server_names_hash_bucket_size size;
默认:server_names_hash_bucket_size 32|64|128;
配置块:http、server、location
2.4 server_names_hash_max_size
语法:server_names_hash_max_size size;
默认:server_names_hash_max_size 512;
配置块:http、server、location
2.5 重定向主机名称的处理
语法:server_name_in_redirect on|off;
默认:server_name_in_redirect on;
配置块:http、server或者location
2.6 location
语法:location [=|~|~*|^~|@] /uri/{...}
配置块:server

3. 文件路径的定义

3.1 以root方式设置资源路径
语法:root path;
默认:root html;
配置块:http、server、locationo、if
3.2 以alias方式设置资源文件
语法:alias path;
配置块:location;
3.3 访问首页
语法:index file...;
默认:index index.html;
配置块:http、server、location
3.4 根据http返回码重定向页面
语法:error_page code[code...][=|=answer-code]uri|@named_location
配置块:http、server、location、if
3.5 是否支持递归的使用error_page
语法:recursive_error_pages [on|off];
默认:recursive_error_pages off;
配置块:http、server、location;
3.6 try_files
语法:try_files path2[path3]uri;
配置块:server、location

4. 内存及磁盘资源的分配

4.1 http包体只存储到磁盘文件中
语法:client_body_in_file_only on|clean|off;
默认:client_body_in_file_only off;
配置块:http、server、location
4.2 http包体尽量写入到一个内存buffer中
语法:client_body_in_single_buffer on|off;
默认:client_body_in_single_buffer off;
配置块:http、server、location
4.3 存储http头部的内存buffer大小
语法:client_header_buffer_size size;
默认:client_header_buffer_size 1k;
配置块:http、server
4.4 存储超大http头部的内存buffer大小
语法:large_client_header_buffers number size;
默认:large_client_header_buffers 48k;
配置块:http、server
4.5 存储http包体的内存buffer的大小
语法:client_body_buffer_size size;
默认:client_body_buffer_size 8k/16k;
配置块:http、server、location
4.6 http包体的临时存放目录
语法:client_body_temp_path dir-path[level1[level2[level3]]]
默认:client_body_temp_path client_body_temp;
配置块:http、server、location
4.7 connection_pool_size
语法:connection_pool_size size;
默认:connection_pool_size 256;
配置块:http、server
4.8 request_pool_size
语法:request_pool_size size;
默认:request_pool_size 4k;
配置块:http、server

5. 网络连接的设置

5.1 读取http头部的超时时间
语法:client_header_timeout time(默认单位:秒);
默认:client_header_timeout 60;
配置块:http、server、location
5.2 读取http包体的超时时间
语法:client_body_timeout time(默认单位:秒);
默认:client_body_timeout 60;
配置块:http、server、location
5.3 发送响应的超时时间
语法:send_timeout time;
默认:send_timeout 60;
配置块:http、server、location
5.4 reset_timeout_connection
语法:reset_timeout_connection on|off;
默认:reset_timeout_connection off;
配置块:http、server、location
5.5 lingering_close
语法:lingering_close off|on|always;
默认:lingering_close on;
配置块:http、server、location
5.6 lingering_time
语法:lingering_time time;
默认:lingering_time 30s;
配置块:http、server、location
5.7 lingering_timeout
语法:lingering_timeout time;
默认:lingering_timeout 5s;
配置块:http、server、location
5.8 对某些浏览器禁用keepalive功能
语法:keepalive_disable [msie6|safari|none]...
默认:keepalive_disablemsie6 safari
配置块:http、server、location
5.9 keepalive超时时间
语法:keepalive_timeout time(默认单位:秒);
默认:keepalive_timeout 75;
配置块:http、server、location
5.10 keepalive长连接上能够承载的最大请求数
语法:keepalive_requests n;
默认:keepalive_requests 100;
配置块:http、server、location
5.11 tcp_nodelay
语法:tcp_nodelay on|off;
默认:tcp_nodelay on;
配置块:http、server、location
5.12 tcp_nopush
语法:tcp_nopush on|off;
默认:tcp_nopush off;
配置块:http、server、location

6. MIME类型的设置

6.1 MIME type与文件扩展的映射
语法:type {...};
配置块:http、server、location
6.2 默认MIME type
语法:default_type MIME-type;
默认:default_type text/plain;
配置块:http、server、location
6.3 types_hash_bucket_size
语法:types_hash_max_size size;
默认:types_hash_max_size 1024;
配置块:http、server、location
6.4 types_hash_max_size
语法:types_hash_max_size size;
默认:types_hash_max_size 1024;
配置块:http、server、location

7. 对客户端请求的限制

7.1 按http方法名限制用户请求
语法:limit_except method...{...}
配置块:location
7.2 http请求包体的最大值
语法:client_max_body_size size;
默认:client_max_body_size 1m;
配置块:http、server、location
7.3 对请求的限速
语法:limit_rate speed;
默认:limit_rate 0;
配置块:http、server、location、if
7.4 limit_rate_after
语法:limit_rate_after time;
默认:limit_rate_after 1m;
配置块:http、server、location、if

8. 文件操作的优化

8.1 sendfile系统调用
语法:sendfile on|off;
默认:sendfile off;
配置块:http、server、location
8.2 AIO系统调用
语法:aio on|off;
默认:aio off;
配置块:http、server、location
8.3 directio
语法:directio size|off;
默认:directio off;
配置块:http、server、location
8.4 directio_alignment
语法:directio_alignment size;
默认:directio_alignment 512;
配置块:http、server、location
8.5 打开文件缓存
语法:open_file_cache max=N[inactive=time]|off;
默认:open_file_cache off;
配置块:http、server、location
8.6 是否缓存打开文件错误的信息
语法:open_file_cache_errors on|off;
默认:open_file_cache_errors off;
配置块:http、server、location
8.7 不被淘汰的最小访问次数
语法:open_file_cache_min_uses number;
默认:open_file_cache_min_uses 1;
配置块:http、server、location
8.8 检验缓存中元素有效性的频率
语法:open_file_cache_valid time;
默认:open_file_cahce_valid 60s;
配置块:http、server、location

9. 对客户端请求的特殊处理

9.1 忽略不合法的http头部
语法:ignore_invalid_headers on|off;
默认:ignore_invalid_headers on;
配置块:http、server
9.2 http头部是否允许下划线
语法:underscores_in_headers on|off;
默认:underscores_in_headers off;
配置块:http、server
9.3 对If-Modified-Since头部的处理策略
语法:if_modified_since [off|exact|before];
默认:if_modified_since exact;
配置块:http、server、location
9.4 文件未找到时是否返回error日志
语法:log_not_found on|off;
默认:log_not_found on;
配置块:http、server、location
9.5 merge_slashes
语法:merge_slashes on|off;
默认:merge_slashes on;
配置块:http、server、location
9.6 DNS解析地址
语法:resolver address...;
配置块:http、server、location
9.7 DNS解析的超时时间
语法:resolver_timeout time;
默认:resolver_timeout 30s;
配置块:http、server、location
9.8 返回错误页面时是否在server中注明nginx版本
语法:server_tokens on|off;
默认:server_tokens on;
配置块:http、server、location

感谢各位的阅读,以上就是“Nginx的基本属性配置”的内容了,经过本文的学习后,相信大家对Nginx的基本属性配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. nginx的location配置
  2. nginx的rewrite配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx

上一篇:C#中StringBuilder内存碎片对性能的影响有哪些

下一篇:Linux中有哪些POSIX规范

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》