For a given vhost, I want to redirect some routes/paths/URIs to HTTPS, while allowing others to be requested on HTTP.

Specifically, I want to allow Artifactory packages to be requested on HTTP, but require that the web UI be accessed via HTTPS.

How can I do this?


First, make sure your server block is listening for requests on both port 80 and 443. Then include a conditional on $scheme and a permanent rewrite.

So to force /webapp and (anything under it) to HTTPS, you would use:

server {
  listen *:443 ssl;
  listen *:80;
  server_name www.example.com;

  if ($scheme != 'https') {
    rewrite ^/(webapp(/.*)?)$ https://$http_host/$1 permanent;

  # ...
  • One needs also to make sure that no HSTS headers are set for the server, otherwise everything will be on HTTPS. – Tero Kilkanen Aug 19 '18 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.