Use a Reverse Proxy for HTTPS Support
=====================================

CodeScene doesn't implement HTTPS support itself. Instead we
recommend that you put a reverse proxy in front of the application if
you need encryption. We recommend `Nginx <https://nginx.org/en/download.html>`_ as
the reverse proxy. The Nginx website provides documentation on
`configuring Nginx for HTTPS <http://nginx.org/en/docs/http/configuring_https_servers.html>`_.

Here is a brief example of an Nginx proxy configuration:

.. code-block:: nginx

    http {

      server {
        listen 80;
        server_name codescene.example.com;
        location / {
          return 301 https://$host$request_uri;
        }
      }

      server {
        listen 443 ssl;
        server_name codescene.example.com;

        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

        location /  {
          proxy_pass http://localhost:3003;
          proxy_redirect http:// $scheme://;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }
      }

The `proxy_redirect <http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect>`_ used above will rewrite all HTTP redirects from upstream
to the current scheme, ie HTTPS. The browser will then receive the correct scheme
directly, avoiding unnecessary round-trips.

There is also a
`Docker-based sample project <https://github.com/empear-analytics/docker-codescene-nginx-self-signed-ssl>`_
that provides CodeScene wrapped by an Nginx reverse proxy with a self-signed certificate. It composes a CodeScene
container and an Nginx container using a small `docker-compose.yml` file.
