ytw asked:
In nginx.conf file, is it possible to rewrite to HTTP or HTTPS based on whether the current connection is secured or not?
Some pseudocode of what I want to do.
location ^~ /test_api {
if (secured connection)
rewrite "/test_api" https://www.somedomain.com/test_api break;
else
rewrite "/test_api" http://www.somedomain.com/test_api break;
}
Thanks.
My answer:
You’re looking for $scheme
.
rewrite /test_api $scheme://www.example.com/test_api break;
View the full question and any other answers on Server Fault.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.