0

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?

Jonathon Reinhart
  • 506
  • 1
  • 8
  • 27

1 Answers1

0

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;
  }

  # ...
}
Jonathon Reinhart
  • 506
  • 1
  • 8
  • 27