Nginx 核心配置-作为上传服务器配置
Nginx核心配置-作为上传服务器配置
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.关键参数说明
client_max_body_size 1m;
设置允许客户端上传单个文件的最大值,默认值为1m,推荐值500M
client_body_buffer_size size;
用于接收每个客户端请求报文的body部分的缓冲区大小;默认16k;超出此大小时,其将被暂存到磁盘上的由下面client_body_temp_path指令所定义的位置。推荐之2048k client_body_temp_path path [level1 [level2 [level3]]];
设定存储客户端请求报文的body部分的临时存储路径及子目录结构和数量,目录名为16进制的数字,使用hash之后的值从后往前截取1位、2位、2位作为文件名:
二.上传服务器参数配置案例
1>.修改主配置文件(在主配置的httpd标签中定义后,会对所有server标签生效,包括加载进来的server标签哟,这样如果有多个虚拟主机需要上传功能,我们只需要在主配置文件配置一份即可)
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf/nginx.conf
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000; events {
worker_connections 100000;
use epoll;
accept_mutex on;
multi_accept on;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
charset utf-8; #当文件大于等于给定大小时,同步(直接)写磁盘,而非写缓存。
directio 4m; #上传文件相关参数
client_max_body_size 10m;
client_body_buffer_size 16k;
client_body_temp_path /yinzhengjie/data/web/nginx/temp 1 2 2; #禁用IE系列的长连接,默认就是禁用了IE的长连接功能.
keepalive_disable msie6; #开启长连接后,返回客户端的会话保持时间为60s,单次长连接累计请求达到指定次数请求或65秒就会被断开,后面的60为发送给客户端应答报文头部中显示的超时时间设置为60s:如不设置
客户端将不显示超时时间。 keepalive_timeout 65 60; #在一次长连接上所允许请求的资源的最大数量
keepalive_requests 3; #导入其他路径的配置文件
include /yinzhengjie/softwares/nginx/conf.d/*.conf;
} [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
2>.修改子配置文件
[root@node101.yinzhengjie.org.cn ~]# vim /yinzhengjie/softwares/nginx/conf.d/share.conf
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/share.conf
server {
listen 80;
server_name node101.yinzhengjie.org.cn; location / {
root /yinzhengjie/data/web/nginx/static;
index index.html;
} location /download {
root /yinzhengjie/data/web/nginx;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
limit_rate 10k;
} location /upload {
root /yinzhengjie/data/web/nginx;
#排除GET方法外,其它方法均可以在当前localtion使用,而且我们只允许172.30.1.108节点来访问。
limit_except GET {
allow 172.30.1.108;
deny all;
}
}
}
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
3>.创建数据目录
[root@node101.yinzhengjie.org.cn ~]# mkdir /yinzhengjie/data/web/nginx/upload #该目录需要自动手动创建出来
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/data/web/nginx/ #使用nginx -t命令时会自动创建client_body_temp_path所对应的目录
total 4
drwxr-xr-x 2 root root 166 Dec 17 14:54 download
-rw-r--r-- 1 root root 43 Dec 17 13:04 index.html
drwxr-xr-x 3 root root 51 Dec 17 13:08 login
drwxr-xr-x 2 root root 44 Dec 17 12:54 static
drwx------ 2 nginx root 6 Dec 17 15:24 temp
drwxr-xr-x 2 root root 6 Dec 17 15:26 upload
[root@node101.yinzhengjie.org.cn ~]#
4>.重新加载nginx的配置文件
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 5023 2840 0 14:48 ? 00:00:00 nginx: worker process
nginx 5024 2840 0 14:48 ? 00:00:00 nginx: worker process
nginx 5025 2840 0 14:48 ? 00:00:00 nginx: worker process
nginx 5026 2840 0 14:48 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root 2840 1 0 09:37 ? 00:00:00 nginx: master process nginx
nginx 5477 2840 7 16:10 ? 00:00:00 nginx: worker process
nginx 5478 2840 9 16:10 ? 00:00:00 nginx: worker process
nginx 5479 2840 10 16:10 ? 00:00:00 nginx: worker process
nginx 5480 2840 11 16:10 ? 00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
5>.IP地址为172.30.1.101的节点上传文件到web服务器
[root@node101.yinzhengjie.org.cn ~]# curl -XPUT /etc/passwd http://node101.yinzhengjie.org.cn/upload #由于nginx只允许172.30.1.108节点可以使用所有方法(GET方法除外),当前IP地址被nginx拒绝了
curl: (3) <url> malformed
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
[root@node101.yinzhengjie.org.cn ~]#
5>.IP地址为172.30.1.108的节点上传文件到web服务器
[root@node108.yinzhengjie.org.cn ~]# curl -XPUT /etc/passwd http://node101.yinzhengjie.org.cn/upload #Nginx已经允许当前节点上传数据,但是程序未支持上传功能。
curl: (3) <url> malformed
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
[root@node108.yinzhengjie.org.cn ~]#
Nginx 核心配置-作为上传服务器配置的更多相关文章
- Nginx 核心配置-作为下载服务器配置
Nginx 核心配置-作为下载服务器配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.无限速版本的下载服务器 1>.查看主配置文件 [root@node101.yinz ...
- Nginx 核心配置详解
目录 Nginx 核心配置详解 Nginx 四层访问控制: Nginx账户认证功能: 自定义错误页面: 自定义访问日志: 检测文件是否存在: 长连接配置: 作为下载服务器配置: 作为上传服务器: 其他 ...
- Nginx 核心配置-可优化配置参数
Nginx 核心配置-可优化配置参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.nginx的官网查看指令帮助信息方法 1>.打开nginx的官网(https://ng ...
- Nginx 核心配置-新建一个web站点
Nginx 核心配置-新建一个web站点 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx基础配置常用参数说明 [root@node101.yinzhengjie.or ...
- 关于editor网页编辑器ueditor.config.js 配置图片上传
最近公司项目在做一个门户网站,其中新闻和简介等部分使用到了ueditor编辑器,但是上级明确指示需要图片上传这个功能,这时却发现图片上传功能不能正常使用,上传时一直报错,网上收了好几个处理办法,都说的 ...
- Nginx 核心配置-长连接配置
Nginx 核心配置-长连接配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.长连接配置参数说明 keepalive_timeout number; 设定保持连接超时时长,0 ...
- Nginx 核心配置-自定义错误页面
Nginx 核心配置-自定义错误页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 生产环境中错误页面一般都是UI或开发工程师提供的,他们已经在软件中定义好了,我们这里就简单写个h ...
- Nginx 核心配置-location的登录账户认证实战篇
Nginx 核心配置-location的登录账户认证实战篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.使用ab命令模拟网站攻击 1>.安装httpd-tools工具 ...
- Nginx 核心配置-单节点实现多域名访问
Nginx 核心配置-单节点实现多域名访问 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.试验环境说明 1>.虚拟机环境说明 [root@node101.yinzheng ...
随机推荐
- ESP8266 LUA脚本语言开发: 准备工作-LUA开发说明
前言 开发Lua需要使用这个软件 注:该软件需要按照JDK 即 JAVA虚拟机,如果没有安装过JDK,请先看JDK安装教程安装JDK USB线连接开发板接入电脑 选择自己的串口号 波特率115200 ...
- linux帮助命令使用
一. help使用 查看ls命令的帮助信息 ls --help # 查看全部 ls --help | less # 分页查看, q退出 二. man手册 同一命令存在于多个章 ...
- P3613 【深基15.例2】寄包柜
传送门 题目大意 往一个\(a[i][j]\) 里边放东西,也可以取走东西,然后查询\(a[i][j]\)里边是什么东西. 思路: 显然我们可以暴力,但是你开不了那么大的数组. 翻了翻dalao们的题 ...
- 第03组 Beta版本演示
队名:不等式方程组 组长博客 组员 340 张逸杰 组长 304 苏凯婷 312 鲍冰如 320 陈荣杰 331 杨锦镔 335 王嵚 336 林家伟 341 黄彬煌 342 黄智锋 343 吴智勇 ...
- 【2019年07月22日】A股最便宜的股票
查看更多A股最便宜的股票:androidinvest.com/CNValueTop/ 便宜指数 = PE + PB + 股息 + ROE,四因子等权,数值越大代表越低估. 本策略只是根据最新的数据来选 ...
- Qt Quick 基本元素初体验
Qt Quick 作为 QML 语言的标准库,提供了很多基本元素和控件来帮助我们构建 Qt Quick 应用,这节我们简要地介绍一些 Qt Quick 元素. 一. 基本可视化项 1.1 Item I ...
- vue学习面向对象,在项目中怎么用呢?
面向对象感觉很牛逼,可是在项目中怎么用呢? 我至今见到的用法,写了一个用户对象. 效果:只要执行了new User(userInfo)就会在cookie,localStorage存放数据. 所以最简单 ...
- Web支持HTTPS的client(HTTP&XML-RPC)
生成Web自签名的证书(在命令行执行以下命令) keytool -genkey -keysize 2048 -validity 3650 -keyalg RSA -dname "CN=Han ...
- Luogu P3879 【[TJOI2010]阅读理解】
前言: 这个题一直有个疑问,最多一千行,每行五千字$1000\times5000=5e6$ $5e6\times26\times4\div1024\div1024\approx496Mb>125 ...
- Git 核心概念
原文链接 Git的核心概念 聪聪的个人网站 本文不是Git使用教学篇,而是偏向理论方面,旨在更加深刻的理解Git,这样才能更好的使用它,让工具成为我们得力的助手. 版本控制系统 Git 是目前世界上最 ...