Hello!
On Mon, Dec 21, 2015 at 9:38 PM, Ted Timmons wrote:
> Here's an example:
>
> access_by_lua '
> if not ngx.var.http_x_forwarded_proto == nil then
> ngx.log(ngx.ERR, "time to redirect.")
> ngx.redirect("https://" .. ngx.var.host, ngx.HTTP_MOVED_PERMANENTLY)
> end
> ';
>
> I'm testing it with this:
>
> curl -H "x-forwarded-proto: https" -D - http://localhost/
>
> Expected output is a Location header and an error.log entry. I see neither.
I've tried your code example locally with the following self-contained
configuration:
location = /t {
access_by_lua_block {
local v = ngx.var.http_x_forwarded_proto
if v == nil then
ngx.log(ngx.ERR, "time to redirect.")
return ngx.redirect("https://" .. ngx.var.host ..
ngx.var.request_uri,
ngx.HTTP_MOVED_PERMANENTLY)
end
}
echo ok;
}
And then test it out with your request:
$ curl -H "x-forwarded-proto: https" -i http://localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.9.7 (no pool)
Date: Tue, 22 Dec 2015 18:14:07 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
ok
$ grep "\[error" t/servroot/logs/error.log
$ curl -H "X-Forwarded-Proto: https" -i http://localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.9.7 (no pool)
Date: Tue, 22 Dec 2015 18:14:45 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
ok
$ grep "\[error" t/servroot/logs/error.log
$ curl -i http://localhost:8080/t
HTTP/1.1 301 Moved Permanently
Server: nginx/1.9.7 (no pool)
Date: Tue, 22 Dec 2015 18:15:11 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://localhost/t
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.9.7 (no pool)</center>
</body>
</html>
$ grep "\[error" t/servroot/logs/error.log
2015/12/22 10:15:11 [error] 120299#0: *3 [lua]
access_by_lua(nginx.conf:47):4: time to redirect., client: 127.0.0.1,
server: localhost, request: "GET /t HTTP/1.1", host: "localhost:8080"
So these are all what you'd expect? When there is no X-Forwarded-Proto
request headers, you initiate a 301 redirect, according to your Lua
code logic. And we can also see that HTTP header names are
case-insensitive. How should I reproduce the problem you have?
Best regards,
-agentzh