add /skynet/pin endpoint and clean up config
This commit is contained in:
parent
c84723b159
commit
ed7c1f71c7
|
@ -325,6 +325,8 @@ server {
|
||||||
location /skynet/skyfile {
|
location /skynet/skyfile {
|
||||||
include /etc/nginx/conf.d/include/cors;
|
include /etc/nginx/conf.d/include/cors;
|
||||||
include /etc/nginx/conf.d/include/sia-auth;
|
include /etc/nginx/conf.d/include/sia-auth;
|
||||||
|
include /etc/nginx/conf.d/include/track-upload;
|
||||||
|
include /etc/nginx/conf.d/include/generate-siapath;
|
||||||
|
|
||||||
limit_req zone=uploads_by_ip burst=100 nodelay;
|
limit_req zone=uploads_by_ip burst=100 nodelay;
|
||||||
limit_req zone=uploads_by_ip_throttled;
|
limit_req zone=uploads_by_ip_throttled;
|
||||||
|
@ -338,18 +340,6 @@ server {
|
||||||
proxy_set_header Expect $http_expect;
|
proxy_set_header Expect $http_expect;
|
||||||
proxy_set_header User-Agent: Sia-Agent;
|
proxy_set_header User-Agent: Sia-Agent;
|
||||||
|
|
||||||
# Extract 2 sets of 2 characters from $request_id and assign to $dir1, $dir2
|
|
||||||
# respectfully. The rest of the $request_id is going to be assigned to $dir3.
|
|
||||||
# We use those variables to automatically generate a unique path for the uploaded file.
|
|
||||||
# This ensures that not all uploaded files end up in the same directory, which is something
|
|
||||||
# that causes performance issues in the renter.
|
|
||||||
# Example path result: /af/24/9bc5ec894920ccc45634dc9a8065
|
|
||||||
if ($request_id ~* "(\w{2})(\w{2})(\w+)") {
|
|
||||||
set $dir1 $1;
|
|
||||||
set $dir2 $2;
|
|
||||||
set $dir3 $3;
|
|
||||||
}
|
|
||||||
|
|
||||||
# access_by_lua_block {
|
# access_by_lua_block {
|
||||||
# -- this block runs only when accounts are enabled
|
# -- this block runs only when accounts are enabled
|
||||||
# if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
# if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
||||||
|
@ -365,25 +355,6 @@ server {
|
||||||
|
|
||||||
# proxy this call to siad endpoint (make sure the ip is correct)
|
# proxy this call to siad endpoint (make sure the ip is correct)
|
||||||
proxy_pass http://siad/skynet/skyfile/$dir1/$dir2/$dir3$is_args$args;
|
proxy_pass http://siad/skynet/skyfile/$dir1/$dir2/$dir3$is_args$args;
|
||||||
|
|
||||||
# register the upload in accounts service (cookies should contain jwt)
|
|
||||||
log_by_lua_block {
|
|
||||||
-- this block runs only when accounts are enabled
|
|
||||||
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
|
||||||
|
|
||||||
local skylink = ngx.header["Skynet-Skylink"]
|
|
||||||
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
|
|
||||||
local http = require("socket.http")
|
|
||||||
local ok, statusCode, headers, statusText = http.request {
|
|
||||||
url = "http://accounts:3000/track/upload/" .. skylink,
|
|
||||||
method = "POST",
|
|
||||||
headers = ngx.req.get_headers()
|
|
||||||
}
|
|
||||||
if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then
|
|
||||||
ngx.log(ngx.ERR, "accounts endpoint /track/upload/" .. skylink .. " failed with error " .. statusCode)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# endpoing implementing resumable file uploads open protocol https://tus.io
|
# endpoing implementing resumable file uploads open protocol https://tus.io
|
||||||
|
@ -405,18 +376,8 @@ server {
|
||||||
location /skynet/pin {
|
location /skynet/pin {
|
||||||
include /etc/nginx/conf.d/include/cors;
|
include /etc/nginx/conf.d/include/cors;
|
||||||
include /etc/nginx/conf.d/include/sia-auth;
|
include /etc/nginx/conf.d/include/sia-auth;
|
||||||
|
include /etc/nginx/conf.d/include/track-upload;
|
||||||
# Extract 2 sets of 2 characters from $request_id and assign to $dir1, $dir2
|
include /etc/nginx/conf.d/include/generate-siapath;
|
||||||
# respectfully. The rest of the $request_id is going to be assigned to $dir3.
|
|
||||||
# We use those variables to automatically generate a unique path for the uploaded file.
|
|
||||||
# This ensures that not all uploaded files end up in the same directory, which is something
|
|
||||||
# that causes performance issues in the renter.
|
|
||||||
# Example path result: /af/24/9bc5ec894920ccc45634dc9a8065
|
|
||||||
if ($request_id ~* "(\w{2})(\w{2})(\w+)") {
|
|
||||||
set $dir1 $1;
|
|
||||||
set $dir2 $2;
|
|
||||||
set $dir3 $3;
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy_set_header User-Agent: Sia-Agent;
|
proxy_set_header User-Agent: Sia-Agent;
|
||||||
proxy_pass http://siad$uri?siapath=$dir1/$dir2/$dir3&$args;
|
proxy_pass http://siad$uri?siapath=$dir1/$dir2/$dir3&$args;
|
||||||
|
@ -433,6 +394,7 @@ server {
|
||||||
include /etc/nginx/conf.d/include/cors;
|
include /etc/nginx/conf.d/include/cors;
|
||||||
include /etc/nginx/conf.d/include/proxy-buffer;
|
include /etc/nginx/conf.d/include/proxy-buffer;
|
||||||
include /etc/nginx/conf.d/include/proxy-cache-downloads;
|
include /etc/nginx/conf.d/include/proxy-cache-downloads;
|
||||||
|
include /etc/nginx/conf.d/include/track-download;
|
||||||
|
|
||||||
# redirect purge calls to separate location
|
# redirect purge calls to separate location
|
||||||
error_page 462 = @purge;
|
error_page 462 = @purge;
|
||||||
|
@ -467,26 +429,6 @@ server {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
# register the download in accounts service (cookies should contain jwt)
|
|
||||||
log_by_lua_block {
|
|
||||||
-- this block runs only when accounts are enabled
|
|
||||||
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
|
||||||
|
|
||||||
local skylink = ngx.header["Skynet-Skylink"]
|
|
||||||
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
|
|
||||||
local http = require("socket.http")
|
|
||||||
local query = table.concat({ "status=" .. ngx.status, "bytes=" .. ngx.var.body_bytes_sent }, "&")
|
|
||||||
local ok, statusCode, headers, statusText = http.request {
|
|
||||||
url = "http://accounts:3000/track/download/" .. skylink .. "?" .. query,
|
|
||||||
method = "POST",
|
|
||||||
headers = ngx.req.get_headers()
|
|
||||||
}
|
|
||||||
if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then
|
|
||||||
ngx.log(ngx.ERR, "accounts endpoint /track/download/" .. skylink .. " failed with error " .. statusCode)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy_read_timeout 600;
|
proxy_read_timeout 600;
|
||||||
proxy_set_header User-Agent: Sia-Agent;
|
proxy_set_header User-Agent: Sia-Agent;
|
||||||
# proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct)
|
# proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Extract 2 sets of 2 characters from $request_id and assign to $dir1, $dir2
|
||||||
|
# respectfully. The rest of the $request_id is going to be assigned to $dir3.
|
||||||
|
# We use those variables to automatically generate a unique path for the uploaded file.
|
||||||
|
# This ensures that not all uploaded files end up in the same directory, which is something
|
||||||
|
# that causes performance issues in the renter.
|
||||||
|
# Example path result: /af/24/9bc5ec894920ccc45634dc9a8065
|
||||||
|
if ($request_id ~* "(\w{2})(\w{2})(\w+)") {
|
||||||
|
set $dir1 $1;
|
||||||
|
set $dir2 $2;
|
||||||
|
set $dir3 $3;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
# register the download in accounts service (cookies should contain jwt)
|
||||||
|
log_by_lua_block {
|
||||||
|
-- this block runs only when accounts are enabled
|
||||||
|
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
||||||
|
|
||||||
|
local skylink = ngx.header["Skynet-Skylink"]
|
||||||
|
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
|
||||||
|
local http = require("socket.http")
|
||||||
|
local query = table.concat({ "status=" .. ngx.status, "bytes=" .. ngx.var.body_bytes_sent }, "&")
|
||||||
|
local ok, statusCode, headers, statusText = http.request {
|
||||||
|
url = "http://accounts:3000/track/download/" .. skylink .. "?" .. query,
|
||||||
|
method = "POST",
|
||||||
|
headers = ngx.req.get_headers()
|
||||||
|
}
|
||||||
|
if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then
|
||||||
|
ngx.log(ngx.ERR, "accounts endpoint /track/download/" .. skylink .. " failed with error " .. statusCode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
# register the upload in accounts service (cookies should contain jwt)
|
||||||
|
log_by_lua_block {
|
||||||
|
-- this block runs only when accounts are enabled
|
||||||
|
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end
|
||||||
|
|
||||||
|
local skylink = ngx.header["Skynet-Skylink"]
|
||||||
|
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
|
||||||
|
local http = require("socket.http")
|
||||||
|
local ok, statusCode, headers, statusText = http.request {
|
||||||
|
url = "http://accounts:3000/track/upload/" .. skylink,
|
||||||
|
method = "POST",
|
||||||
|
headers = ngx.req.get_headers()
|
||||||
|
}
|
||||||
|
if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then
|
||||||
|
ngx.log(ngx.ERR, "accounts endpoint /track/upload/" .. skylink .. " failed with error " .. statusCode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
Reference in New Issue