Take the 2-minute tour ×

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;
        rewrite "/test_api"   http://www.somedomain.com/test_api      break;


share|improve this question

1 Answer 1

up vote 1 down vote accepted

You're looking for $scheme.

rewrite /test_api $scheme://www.example.com/test_api break;
share|improve this answer

Your Answer


