I'm trying to get a simple redirect working on my nginx server. I am receiving the 302 response code back, but the Location
header is not set. What am I missing?
My minimal case (with a hard coded image):
location /redirectme {
return 302 https://www.google.com/logos/doodles/2016/childrens-day-2016-brazil-5739205150900224-hp2x.jpg;
}
My actual use case (redirect the user to the URL passed into the url
query parameter):
location /redirectme {
return 302 $arg_url
}
Another config that I tried (manually setting the Location header):
location /redirectme {
add_header Location $arg_url;
return 302;
}
None of these work in actually redirecting the client to the new URL (only returning the 302). The rest of my web app works great, just not this redirection piece. If it makes a difference, I'm working within an ssl server {...}
block. Any ideas? Thanks!
----- UPDATE ------
Here is the entire server
block...
server {
listen 443;
server_name myserver.com;
access_log /path-to/myserver.com-ssl.access.log;
ssl on;
ssl_certificate /path-to/myserver.com.crt;
ssl_certificate_key /path-to/myserver.com.key;
ssl_client_certificate /path-to/clientkey.pem;
ssl_verify_client on;
ssl_verify_depth 1;
keepalive_timeout 5;
root /srv/www/myserver/public/;
location /redirectme {
return 302 $arg_url;
}
location / {
try_files $uri/index.html $uri/index.htm @unicorn;
}
location @unicorn {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-CLIENT-VERIFY $ssl_client_verify;
proxy_redirect off;
proxy_read_timeout 60;
proxy_send_timeout 60;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://unicorn_myserver.com;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /srv/www/myserver/public/;
}
}
And the response from doing curl -i
:
HTTP/1.1 302 Found
Content-Type: application/json
Content-Length: 0
Connection: keep-alive
Date: Fri, 14 Oct 2016 18:37:32 GMT
x-amzn-RequestId: 44e865b2-923d-11e6-a60a-5f6291eee9a8
X-Cache: Miss from cloudfront
Via: 1.1 aa89533ad2ec5e0edba466c9920bd000.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 7dzQ9JQK380hFD-nFyJxm6mIWT5D4mWzvCbSAhDaa-pHwpF4oZHszw==
It may also be relevant (I don't understand how, but maybe) that I have Amazon API Gateway sitting in front of my requests, directly proxying them to my server (note: the ssl_client_certificate /path-to/clientkey.pem;
is configured to only accept requests from API Gateway).
0 Answers