user1387717 February 2016

nginx redirect multiple servers to SSL

I have this code. I just want each of the server_name in the list to redirect to its own name https. But, if I do http://beta.example.com, it redirects to https://api.example.com (or whatever the first item in the list is)

server {
    listen         80;
    server_name    api.example.com beta.example.com apibeta.example.com nodebeta.example.com app.example.com;
    return         301 https://$server_name$request_uri;
}

Answers


StephenKing February 2016

You should be able to use the $host variable instead:

server {
    listen         80;
    server_name    api.example.com beta.example.com apibeta.example.com nodebeta.example.com app.example.com;
    return         301 https://$host$request_uri;
}

Post Status

Asked in February 2016
Viewed 2,488 times
Voted 7
Answered 1 times

Search




Leave an answer