server {
    listen 9001;

    include /etc/nginx/includes/server_params.conf;
    include /etc/nginx/includes/proxy_params.conf;

    ssl_certificate /ssl/%%certfile%%;
    ssl_certificate_key /ssl/%%keyfile%%;

    proxy_buffering off;
    gzip_static off;
    client_max_body_size 0;

    location / {
      # Proxy pass
      proxy_pass http://localhost:9000;

      # Next three lines allow websockets
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      # Improve ip handling
      proxy_hide_header X-Powered-By;
      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;
      proxy_set_header Accept-Encoding "";
      proxy_read_timeout 90;

      # Ensure the backend knows the correct host
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Host $http_host;

	  # Correct base_url
      absolute_redirect off;
      sub_filter_once off;
      sub_filter_types *;
      sub_filter %%base_subpath%% /;

      # Rewrite URLs in the response
      sub_filter localhost:9000 %%BASE_URL%%;

    }
}
