Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx SSL从内部位置重定向_Nginx_Lua_Openresty - Fatal编程技术网

Nginx SSL从内部位置重定向

Nginx SSL从内部位置重定向,nginx,lua,openresty,Nginx,Lua,Openresty,我正在用nginx做一些非常糟糕的事情。这是鸟瞰图 nginx在无数个S3存储桶之间扮演代理角色。为了确定正确的bucket,我在OpenResty平台上使用Lua脚本 因此,首先请求进入/位置并由Lua脚本处理 location / { listen 8001; server_name $hostname; access_by_lua_file '/srv/hostingrouter/live/hostingrouter/storerouter.lua'; proxy_pass

我正在用nginx做一些非常糟糕的事情。这是鸟瞰图

nginx在无数个S3存储桶之间扮演代理角色。为了确定正确的bucket,我在OpenResty平台上使用Lua脚本

因此,首先请求进入
/
位置并由Lua脚本处理

location / {
  listen 8001;
  server_name $hostname;
  access_by_lua_file '/srv/hostingrouter/live/hostingrouter/storerouter.lua';
  proxy_pass http://$remote;
}

location ~ /s3/(?<s3_key>.+) {
  internal;
  proxy_pass $s3;
  rewrite .* /$s3_key break;
}
棘手的部分是Lua脚本还执行一些其他重定向。但只有在上面显示的特定情况下,我才需要将URL从HTTP重写为HTTPS

我相信
重写http://https://break
不起作用,因为匹配的路径没有scheme(我也尝试过,但它不起作用)。此外,我还尝试了条件重定向:

if ($scheme = http) {
  return 301 https://$host$request_uri;
}
但它导致了一个循环重定向


如何从内部位置从HTTP重定向到HTTPS?

好的,答案是在
ngx.exec
之前进行
ngx.redirect
(即在Lua文件中)。无需在nginx.conf中进行特殊处理

好的,答案是在
ngx.exec
之前(即在Lua文件中)进行
ngx.redirect
。无需在nginx.conf中进行特殊处理