{% if RUN_LMS %}
upstream lms-backend {
    server lms:8000 fail_timeout=0;
}

server {
  listen 80;
  server_name {{ LMS_HOST }} preview.{{ LMS_HOST }};

  access_log /var/log/nginx/access.log tutor;
  client_max_body_size 4M;
  server_tokens off;

  rewrite ^(.*)/favicon.ico$ /static/images/favicon.ico last;

  location @proxy_to_lms_app {
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_pass http://lms-backend;
  }

  location / {
    try_files $uri @proxy_to_lms_app;
  }

  # /login?next=<any image> can be used by 3rd party sites in <img> tags to
  # determine whether a user on their site is logged into edX.
  # The most common image to use is favicon.ico.
  location /login {
    if ( $arg_next ~* "favicon.ico" ) {
      return 403;
    }
    try_files $uri @proxy_to_lms_app;
  }

  # Need a separate location for the image uploads endpoint to limit upload sizes
  location ~ ^/api/profile_images/[^/]*/[^/]*/upload$ {
    try_files $uri @proxy_to_lms_app;
    client_max_body_size 1049576;
  }

  {{ patch("nginx-lms")|indent(2) }}
}
{% endif %}
