cleanup
This commit is contained in:
@@ -1,264 +1,33 @@
|
||||
|
||||
|
||||
# Resty Function
|
||||
|
||||
* [1.图片上传](#1)
|
||||
* [2.图片拼接](#2)
|
||||
* [4.图片下载](#3)
|
||||
|
||||
------
|
||||
## 前置安装
|
||||
|
||||
- 安装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;;";
|
||||
```
|
||||
|
||||
<h2 id="1">1.图片上传</h2>
|
||||
|
||||
- music-room配置
|
||||
|
||||
```nginx configuration
|
||||
# 子域名配置文件路径
|
||||
# /usr/local/openresty/nginx/conf.d/music-room.conf
|
||||
|
||||
# server contex 中添加文件存储路径变量
|
||||
set $store_dir "/file_upload/"; # 文件存储路径
|
||||
|
||||
# server contex 中添加location
|
||||
|
||||
# Upload image file
|
||||
location /upload_image {
|
||||
content_by_lua_file /usr/local/openresty/resty_funcs/upload_image.lua;
|
||||
}
|
||||
```
|
||||
|
||||
- 添加lua脚本
|
||||
|
||||
将file_upload文件夹下的upload_image.lua 拷贝到如下路径
|
||||
put `upload.lua` into:
|
||||
|
||||
```bash
|
||||
/usr/local/openresty/resty_funcs
|
||||
.
|
||||
└── upload_image.lua
|
||||
/usr/local/opt/openresty/nginx/resty_funcs
|
||||
```
|
||||
|
||||
- 测试curl命令
|
||||
post file:
|
||||
|
||||
```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
|
||||
$ curl --location --request POST 'localhost/upload' \
|
||||
--form '=@"/Users/weli/works/task_server/src/test/resources/file_example_JPG_100kB.jpeg"'
|
||||
```
|
||||
|
||||
⚠️ **./test_files/test0.jpg ./test_files/test1.jpg ./test_files/test2.jpg 为三张上传拼接的图片的路径和文件名**
|
||||
nginx config
|
||||
|
||||
```bash
|
||||
* Trying 152.136.103.69...
|
||||
* TCP_NODELAY set
|
||||
* Connected to music-room.alchemy-studio.cn (152.136.103.69) port 443 (#0)
|
||||
* ALPN, offering h2
|
||||
* ALPN, offering http/1.1
|
||||
* successfully set certificate verify locations:
|
||||
* CAfile: /etc/ssl/cert.pem
|
||||
CApath: none
|
||||
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
|
||||
* TLSv1.2 (IN), TLS handshake, Server hello (2):
|
||||
* TLSv1.2 (IN), TLS handshake, Certificate (11):
|
||||
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
|
||||
* TLSv1.2 (IN), TLS handshake, Server finished (14):
|
||||
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
|
||||
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
|
||||
* TLSv1.2 (OUT), TLS handshake, Finished (20):
|
||||
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
|
||||
* TLSv1.2 (IN), TLS handshake, Finished (20):
|
||||
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
|
||||
* ALPN, server accepted to use http/1.1
|
||||
* Server certificate:
|
||||
* subject: CN=music-room.alchemy-studio.cn
|
||||
* start date: May 16 05:38:01 2021 GMT
|
||||
* expire date: Aug 14 05:38:01 2021 GMT
|
||||
* subjectAltName: host "music-room.alchemy-studio.cn" matched cert's "music-room.alchemy-studio.cn"
|
||||
* issuer: C=US; O=Let's Encrypt; CN=R3
|
||||
* SSL certificate verify ok.
|
||||
> POST /upload_image HTTP/1.1
|
||||
> Host: music-room.alchemy-studio.cn
|
||||
> User-Agent: curl/7.64.1
|
||||
> Accept: */*
|
||||
> Content-Length: 299590
|
||||
> Content-Type: multipart/form-data; boundary=------------------------67148dd99aa78bdc
|
||||
> Expect: 100-continue
|
||||
>
|
||||
< HTTP/1.1 100 Continue
|
||||
* We are completely uploaded and fine
|
||||
< HTTP/1.1 200 OK
|
||||
< Server: openresty/1.19.3.2
|
||||
< Date: Thu, 22 Jul 2021 12:01:51 GMT
|
||||
< Content-Type: application/octet-stream
|
||||
< Transfer-Encoding: chunked
|
||||
< Connection: keep-alive
|
||||
<
|
||||
-->> POST : Upload origin image is test0.jpg
|
||||
|
||||
|
||||
Open file ok 82e3830b-c6ee-45cd-85c6-246682c087aa.jpg
|
||||
|
||||
|
||||
Insert upload image table 1 with /file_upload/82e3830b-c6ee-45cd-85c6-246682c087aa.jpg
|
||||
|
||||
|
||||
-->> POST : Upload origin image is test1.jpg
|
||||
|
||||
|
||||
Open file ok f67ece02-cb5c-48f8-9ff9-e56c69239b15.jpg
|
||||
|
||||
|
||||
Insert upload image table 2 with /file_upload/f67ece02-cb5c-48f8-9ff9-e56c69239b15.jpg
|
||||
|
||||
|
||||
-->> POST : Upload origin image is test2.jpg
|
||||
|
||||
|
||||
Open file ok 992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
|
||||
|
||||
|
||||
Insert upload image table 3 with /file_upload/992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
|
||||
|
||||
|
||||
Show all upload files
|
||||
|
||||
Save upload file is : /file_upload/82e3830b-c6ee-45cd-85c6-246682c087aa.jpg
|
||||
|
||||
|
||||
Save upload file is : /file_upload/f67ece02-cb5c-48f8-9ff9-e56c69239b15.jpg
|
||||
|
||||
|
||||
Save upload file is : /file_upload/992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
|
||||
|
||||
|
||||
Input images list : /file_upload/82e3830b-c6ee-45cd-85c6-246682c087aa.jpg /file_upload/f67ece02-cb5c-48f8-9ff9-e56c69239b15.jpg /file_upload/992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg
|
||||
|
||||
|
||||
Output image is : /file_upload/553120d6-879d-4c9f-a74a-8319b7903642.jpg
|
||||
|
||||
|
||||
/usr/local/ImageMagick/bin/magick convert -append /file_upload/82e3830b-c6ee-45cd-85c6-246682c087aa.jpg /file_upload/f67ece02-cb5c-48f8-9ff9-e56c69239b15.jpg /file_upload/992da1f2-9a9e-41e2-a14d-9d57aa07dcd2.jpg /file_upload/553120d6-879d-4c9f-a74a-8319b7903642.jpg
|
||||
|
||||
|
||||
|
||||
* Connection #0 to host music-room.alchemy-studio.cn left intact
|
||||
* Closing connection 0
|
||||
```
|
||||
/usr/local/etc/openresty/nginx.conf
|
||||
```
|
||||
|
||||
- 查看上传文件和拼接文件
|
||||
|
||||
```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;
|
||||
location /upload {
|
||||
content_by_lua_file /usr/local/opt/openresty/nginx/resty_funcs/upload.lua;
|
||||
}
|
||||
```
|
||||
|
||||
- 添加lua脚本
|
||||
enable log:
|
||||
|
||||
```bash
|
||||
/usr/local/openresty/resty_funcs
|
||||
.
|
||||
└── image_append.lua
|
||||
```
|
||||
error_log /usr/local/etc/openresty/logs/error.log;
|
||||
```
|
||||
|
||||
<h2 id="3">3.图片下载</h2>
|
||||
|
||||
- music-room配置-
|
||||
|
||||
```nginx configuration
|
||||
# 子域名配置文件路径
|
||||
# /usr/local/openresty/nginx/conf.d/music-room.conf
|
||||
|
||||
# server contex 中添加location
|
||||
|
||||
#Static file server
|
||||
location /file_upload {
|
||||
default_type "";
|
||||
alias /file_upload/;
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
autoindex_localtime on;
|
||||
}
|
||||
#Download image files
|
||||
location /download_image {
|
||||
rewrite_by_lua_block{
|
||||
-- Get download image id
|
||||
local download_image_id = string.match(ngx.var.request_uri, ".*/(.*)$")
|
||||
ngx.log(ngx.INFO , "Download image id: " .. download_image_id)
|
||||
|
||||
-- Set redirect uri
|
||||
--local uri = "/internal_file_upload/" .. download_image_id .. ".jpg"
|
||||
--return ngx.exec(uri)
|
||||
|
||||
local uri = "/file_upload/" .. download_image_id .. ".jpg"
|
||||
return ngx.exec(uri, {a = download_image_id})
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- wget测试
|
||||
|
||||
```bash
|
||||
wget http://localhost:8080/download_image/{download_image_uuid}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user