modify README.md

This commit is contained in:
李勇
2021-08-07 16:28:15 +08:00
parent f7586cee44
commit 106e01cf0e
2 changed files with 88 additions and 73 deletions
+88 -73
View File
@@ -1,14 +1,44 @@
# 部署文件上传功能
# Resty Function
* [1.图片上传](#1)
* [2.图片拼接](#2)
------
## 前置安装
- 安装opm
```bash
sudo dnf -f install dnf -y install openresty-opm
```
- 安装 lua-resty-jit-uuid https://github.com/thibaultcha/lua-resty-jit-uuid
```bash
opm get thibaultcha/lua-resty-jit-uuid
```
- 通用命令 重启服务
```bash
$ sudo openresty -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
#首先要openresty nginx配置文件无误
$ sudo systemctl restart openresty
#重启openresty服务不报错
```
## nginx根配置
- 配置openresty
```nginx configuration
# 配置文件路径
# /usr/local/openresty/nginx/conf/nginx.conf
# http contex 中添加lua脚本的路径
lua_package_path "/usr/local/openresty/resty_funcs/?.lua;;";
```
```nginx configuration
# 配置文件路径
# /usr/local/openresty/nginx/conf/nginx.conf
# http contex 中添加lua脚本的路径
lua_package_path "/usr/local/openresty/resty_funcs/?.lua;;";
```
<h2 id="1">1.图片上传</h2>
- music-room配置
```nginx configuration
# 子域名配置文件路径
# /usr/local/openresty/nginx/conf.d/music-room.conf
@@ -17,66 +47,28 @@
set $store_dir "/file_upload/"; # 文件存储路径
# server contex 中添加location
# Test location
location /test_hello_world {
#设置content type
default_type text/html ;
# HTTP Status Code 和 内容
return 200 "hello world! ";
}
# Upload image file
location /upload_image {
content_by_lua_file /usr/local/openresty/resty_funcs/upload_image.lua;
}
#Image append
location /image_append {
content_by_lua_file /usr/local/openresty/nginx/conf/lua/image_append.lua;
}
```
- 安装opm
```bash
sudo dnf -f install dnf -y install openresty-opm
```
- 安装 lua-resty-jit-uuid https://github.com/thibaultcha/lua-resty-jit-uuid
```bash
opm get thibaultcha/lua-resty-jit-uuid
```
- 添加lua脚本
将file_upload文件夹下的所有文件copy到如下路径
```bash
/usr/local/openresty/resty_funcs
.
└── upload_image.lua
```
- 重启服务
```bash
$ sudo openresty -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
#首先要openresty nginx配置文件无误
$ sudo systemctl restart openresty
#重启openresty服务不报错
```
将file_upload文件夹下的upload_image.lua 拷贝到如下路径
```bash
/usr/local/openresty/resty_funcs
.
└── upload_image.lua
```
- 测试curl命令
```bash
curl -v -F 'up_load_json=@./test_files/tile-0.jpg' -F 'up_load_json=@./test_files/tile-1.jpg' -F 'up_load_json=@./test_files/tile-2.jpg' https://music-room.alchemy-studio.cn/upload_image
```
```bash
curl -v -F 'up_load_json=@./test_files/tile-0.jpg' -F 'up_load_json=@./test_files/tile-1.jpg' -F 'up_load_json=@./test_files/tile-2.jpg' https://music-room.alchemy-studio.cn/upload_image
```
⚠️ **./test_files/test0.jpg ./test_files/test1.jpg ./test_files/test2.jpg 为三张上传拼接的图片的路径和文件名**
⚠️ **./test_files/test0.jpg ./test_files/test1.jpg ./test_files/test2.jpg 为三张上传拼接的图片的路径和文件名**
```bash
* Trying 152.136.103.69...
* TCP_NODELAY set
@@ -174,25 +166,48 @@
* Closing connection 0
```
- 查看上传文件和拼接文件
- 查看上传文件和拼接文件
```bash
$ pwd
/file_upload
$ ls -l
总用量 1440
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 08916bcf-93f4-4a2a-8d39-0e11174fdb90.jpg
-rw-rw-rw- 1 nobody nobody 35979 7月 22 11:46 52b2a24d-da6c-41e8-8cdb-2eab371eb56f.jpg
-rw-rw-rw- 1 nobody nobody 298648 7月 22 20:01 553120d6-879d-4c9f-a74a-8319b7903642.jpg
-rw-rw-rw- 1 nobody nobody 298648 7月 21 22:25 6143c43c-e2ab-4002-b391-9f82f6008931.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 22 20:01 82e3830b-c6ee-45cd-85c6-246682c087aa.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 8f2cd5d0-09f6-4be7-9829-3a12e92b81d3.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 22 20:01 992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
-rw-rw-rw- 1 nobody nobody 6109 7月 22 11:46 9c831637-7de6-4255-8878-f2069b8f4f08.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 9ec1a383-9678-4c16-834f-57b4d7f87a1d.jpg
```
```bash
$ pwd
/file_upload
$ ls -l
总用量 1440
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 08916bcf-93f4-4a2a-8d39-0e11174fdb90.jpg
-rw-rw-rw- 1 nobody nobody 35979 7月 22 11:46 52b2a24d-da6c-41e8-8cdb-2eab371eb56f.jpg
-rw-rw-rw- 1 nobody nobody 298648 7月 22 20:01 553120d6-879d-4c9f-a74a-8319b7903642.jpg
-rw-rw-rw- 1 nobody nobody 298648 7月 21 22:25 6143c43c-e2ab-4002-b391-9f82f6008931.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 22 20:01 82e3830b-c6ee-45cd-85c6-246682c087aa.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 8f2cd5d0-09f6-4be7-9829-3a12e92b81d3.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 22 20:01 992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
-rw-rw-rw- 1 nobody nobody 6109 7月 22 11:46 9c831637-7de6-4255-8878-f2069b8f4f08.jpg
-rw-rw-rw- 1 nobody nobody 99699 7月 21 22:25 9ec1a383-9678-4c16-834f-57b4d7f87a1d.jpg
```
<h2 id="2">2.图片拼接</h2>
- music-room配置
```nginx configuration
# 子域名配置文件路径
# /usr/local/openresty/nginx/conf.d/music-room.conf
# server contex 中添加文件存储路径变量
set $store_dir "/file_upload/"; # 文件存储路径
# server contex 中添加location
#Image append
location /image_append {
content_by_lua_file /usr/local/openresty/nginx/conf/lua/image_append.lua;
}
```
- 添加lua脚本
将file_upload文件夹下的image_append拷贝到如下路径
```bash
/usr/local/openresty/resty_funcs
.
└── image_append.lua
```