# tethys_nginx.conf

# the upstream component nginx needs to connect to
upstream channels-backend {
    server 127.0.0.1:{{ port }};
}
# configuration of the server
server {
    # the port your site will be served on
    listen      {{ server_port }}{% if ssl %} ssl{% endif %};

    {%- if ssl %}
    ssl_certificate {{ ssl_cert }}
    ssl_certificate_key {{ ssl_key }}
    {%- endif %}

    # the domain name it will serve for
    server_name {{ hostname }}; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size {{ client_max_body_size }};   # adjust to taste

    {% for directive in additional_directives %}
    {{ directive }}
    {%- endfor %}

    # Tethys Workspaces
    location /workspaces  {
    internal;
        alias {{ workspaces_root }};  # your Tethys workspaces files - amend as required
    }

    location /static {
        alias {{ static_root }}; # your Tethys static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
        proxy_pass http://channels-backend;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        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-Host $server_name;
    }
}