Skip to content

Reverse Proxy Setup

This page explains how to run CosMO behind a reverse proxy (Apache, Nginx, or IIS). A reverse proxy lets you terminate TLS (HTTPS), use a friendly host name, and serve CosMO alongside other applications on the same host.

CosMO relies on WebSocket connections for live features (background-job progress, notifications, chat). Getting the WebSocket configuration right is the most important part of this guide — most proxy problems come from WebSocket traffic being buffered or timed out.


How CosMO serves traffic

CosMO is a single application that serves everything on one HTTP port: the user interface, the API, static assets, login/logout, and the WebSocket endpoint. The default port is 8080; check the server.port setting in your configuration file if you are unsure.

The proxy needs to forward all paths to CosMO, with two special considerations:

  • WebSocket endpoint at /stomp-endpoint/ — this needs WebSocket upgrade support, no response buffering, and a generous timeout (see below).
  • Forwarded headers — the proxy must tell CosMO the original scheme and host so it can build correct links and redirects.

The WebSocket endpoint

CosMO's live messaging uses a connection at /stomp-endpoint/. It opens as a normal HTTPS request and is then upgraded to a WebSocket. Where native WebSockets are unavailable, it falls back to a long-lived streaming HTTP request. Either way the proxy must not buffer this traffic and must allow the connection to stay open. CosMO sends a heartbeat every 10 seconds, so any read/idle timeout shorter than that will repeatedly drop the connection.

The endpoint also requires an authenticated session — the proxy just forwards it correctly; see Security & Secrets.

Requirements checklist

Whichever proxy you use, the configuration must:

  • Forward all requests to CosMO's host and port.
  • Upgrade WebSocket connections on /stomp-endpoint/ (pass the Upgrade and Connection headers).
  • Disable response buffering for /stomp-endpoint/.
  • Use a read/idle timeout of at least 60 seconds (longer is fine) for /stomp-endpoint/.
  • Send the X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-For headers, and preserve the original Host header.
  • Allow request bodies of at least 100 MB so large file uploads succeed.

Forwarded headers and HTTPS

When the proxy terminates TLS and forwards plain HTTP to CosMO, you must send X-Forwarded-Proto: https. Without it, CosMO generates http:// links and redirects, which breaks HTTPS redirects and Single Sign-On (SAML / OIDC) logins.

In the examples below, assume CosMO listens on 127.0.0.1:8080 over plain HTTP, and the proxy terminates TLS for cosmo.example.com.


Set the Public URL in CosMO

Behind a reverse proxy, the address users type in their browser (https://cosmo.example.com) is different from the address CosMO listens on (http://127.0.0.1:8080). CosMO needs to know its public address so it can build correct absolute links — most importantly the Single Sign-On (SAML / OIDC) callback URLs that must be registered with your identity provider.

Set this with the CosMO configuration tool:

  1. Open the configuration tool and go to the Server tab.
  2. Set the Public URL field to the full public base address, including the scheme and (if used) the context path — for example:
  3. https://cosmo.example.com (root deployment), or
  4. https://host.example.com/cosmo (sub-path deployment, see below).
  5. Save and restart the CosMO service.

This corresponds to the cosmo.public-url setting in application.yml:

cosmo:
  public-url: https://cosmo.example.com

Tip

Leave the Public URL blank only for local development — CosMO then falls back to http(s)://localhost:<port>. For any proxied or production deployment, set it.

Note

Set the Public URL in addition to the X-Forwarded-* headers from the proxy — they work together. The forwarded headers cover per-request URL building, while the Public URL provides a fixed, authoritative base address for the SSO callback URLs.


Nginx

CosMO at the root (https://cosmo.example.com/)

# /etc/nginx/conf.d/cosmo.conf

upstream cosmo_backend {
    server 127.0.0.1:8080;
    keepalive 32;
}

# Maps the Upgrade header so WebSocket connections are handled correctly.
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl http2;
    server_name cosmo.example.com;

    ssl_certificate     /etc/ssl/certs/cosmo.crt;
    ssl_certificate_key /etc/ssl/private/cosmo.key;

    # Match CosMO's 100 MB upload limit.
    client_max_body_size 100m;

    # --- WebSocket endpoint ----------------------------------------------
    location /stomp-endpoint/ {
        proxy_pass http://cosmo_backend;

        proxy_http_version 1.1;
        proxy_set_header Upgrade    $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;
        proxy_set_header X-Forwarded-Host  $host;

        # Never buffer; allow long-lived connections.
        proxy_buffering off;
        proxy_read_timeout  3600s;
        proxy_send_timeout  3600s;
    }

    # --- Everything else --------------------------------------------------
    location / {
        proxy_pass http://cosmo_backend;

        proxy_http_version 1.1;
        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;
        proxy_set_header X-Forwarded-Host  $host;
    }
}

# Optional: redirect HTTP to HTTPS
server {
    listen 80;
    server_name cosmo.example.com;
    return 301 https://$host$request_uri;
}

CosMO under a sub-path

See Serving CosMO under a sub-path below first, then forward the prefix unchanged:

location /cosmo/stomp-endpoint/ {
    proxy_pass http://cosmo_backend;        # no path after the port
    proxy_http_version 1.1;
    proxy_set_header Upgrade    $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host              $host;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_buffering off;
    proxy_read_timeout 3600s;
}

location /cosmo/ {
    proxy_pass http://cosmo_backend;        # passes /cosmo/... straight through
    proxy_http_version 1.1;
    proxy_set_header Host              $host;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    client_max_body_size 100m;
}

# Another application served at the site root
location / {
    root /var/www/landing;
}

Keep the prefix

Do not add a trailing slash to proxy_pass http://cosmo_backend/; here — that strips the /cosmo prefix before forwarding, and CosMO (configured with a /cosmo context path) will return 404s. Keep the prefix intact.


Apache (httpd)

Enable the required modules:

a2enmod proxy proxy_http proxy_wstunnel headers ssl rewrite
systemctl restart apache2

proxy_wstunnel provides WebSocket support.

CosMO at the root

<VirtualHost *:443>
    ServerName cosmo.example.com

    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/cosmo.crt
    SSLCertificateKeyFile /etc/ssl/private/cosmo.key

    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "https"

    # --- WebSocket: route the upgrade handshake first --------------------
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule ^/stomp-endpoint/(.*)$ ws://127.0.0.1:8080/stomp-endpoint/$1 [P,L]

    # Streaming/polling fallback (plain HTTP, but must not be buffered).
    ProxyPass        /stomp-endpoint/ http://127.0.0.1:8080/stomp-endpoint/ flushpackets=on
    ProxyPassReverse /stomp-endpoint/ http://127.0.0.1:8080/stomp-endpoint/

    # --- Everything else -------------------------------------------------
    ProxyPass        / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    # Long timeout so the 10s heartbeats don't trip the proxy.
    ProxyTimeout 3600

    LimitRequestBody 104857600        # 100 MB
</VirtualHost>

Order matters

The /stomp-endpoint/ rules must appear before the catch-all ProxyPass /. Apache matches these directives top to bottom.

CosMO under a sub-path

See Serving CosMO under a sub-path, then forward the prefix verbatim:

<VirtualHost *:443>
    ServerName host.example.com
    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/host.crt
    SSLCertificateKeyFile /etc/ssl/private/host.key

    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto "https"

    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule ^/cosmo/stomp-endpoint/(.*)$ ws://127.0.0.1:8080/cosmo/stomp-endpoint/$1 [P,L]

    ProxyPass        /cosmo/stomp-endpoint/ http://127.0.0.1:8080/cosmo/stomp-endpoint/ flushpackets=on
    ProxyPassReverse /cosmo/stomp-endpoint/ http://127.0.0.1:8080/cosmo/stomp-endpoint/

    ProxyPass        /cosmo/ http://127.0.0.1:8080/cosmo/
    ProxyPassReverse /cosmo/ http://127.0.0.1:8080/cosmo/

    ProxyTimeout 3600
    LimitRequestBody 104857600

    # The site root can be served by Apache itself or another backend.
    DocumentRoot /var/www/landing
</VirtualHost>

Keep the /cosmo/ prefix on both sides of each ProxyPass — the path the browser uses must match the context path CosMO is configured with.


IIS (Windows)

IIS needs three components installed:

  1. Application Request Routing (ARR) — the reverse-proxy engine (download from Microsoft).
  2. URL Rewrite — routes incoming requests.
  3. WebSocket Protocol — a Windows feature: Server Manager → Add Roles and Features → Web Server (IIS) → Application Development → WebSocket Protocol.

Then enable proxying: IIS Manager → server node → Application Request Routing Cache → Server Proxy Settings → tick "Enable proxy".

Disable ARR response buffering

In the same Server Proxy Settings dialog, set Response buffer threshold (KB) = 0. ARR buffers proxied responses by default, which breaks CosMO's live updates. Setting the threshold to 0 lets messages stream through immediately.

CosMO at the root

Create a site bound to cosmo.example.com:443 (with your TLS certificate) and place this web.config at its root:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <webSocket enabled="true" pingInterval="00:00:30" />
    <rewrite>
      <rules>
        <rule name="Proxy to CosMO" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="http://127.0.0.1:8080/{R:1}" />
          <serverVariables>
            <set name="HTTP_X_FORWARDED_PROTO" value="https" />
            <set name="HTTP_X_FORWARDED_HOST" value="{HTTP_HOST}" />
          </serverVariables>
        </rule>
      </rules>
    </rewrite>
    <security>
      <requestFiltering>
        <!-- 100 MB in bytes -->
        <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

To allow the forwarded-header server variables, add them to ARR's allowed list: URL Rewrite → View Server Variables → Add HTTP_X_FORWARDED_PROTO and HTTP_X_FORWARDED_HOST.

WebSocket upgrades are handled automatically once the WebSocket feature is installed and <webSocket enabled="true" /> is present.

CosMO under a sub-path

See Serving CosMO under a sub-path, then add a rule that matches the /cosmo prefix and forwards it without stripping it:

<rule name="Proxy to CosMO subpath" stopProcessing="true">
  <match url="^cosmo/(.*)" />
  <action type="Rewrite" url="http://127.0.0.1:8080/cosmo/{R:1}" />
  <serverVariables>
    <set name="HTTP_X_FORWARDED_PROTO" value="https" />
    <set name="HTTP_X_FORWARDED_HOST" value="{HTTP_HOST}" />
  </serverVariables>
</rule>

The rewrite target keeps /cosmo/ so the forwarded path matches CosMO's configured context path.


Serving CosMO under a sub-path

You may want one host that serves another application at / and CosMO at /cosmo. The correct way to do this is to tell CosMO that it lives at /cosmo, and have the proxy forward that prefix unchanged.

Set the context path in CosMO's configuration file (application.yml):

server:
  servlet:
    context-path: /cosmo      # default is empty (root)

After restarting CosMO, it serves at http://host:8080/cosmo/..., including the WebSocket endpoint at http://host:8080/cosmo/stomp-endpoint/.... Point the proxy rules (shown in each section above) at that, keeping the /cosmo prefix on both sides.

Do not strip the prefix at the proxy

Always set the context path in CosMO and forward the prefix unchanged. If you instead strip /cosmo at the proxy, the application's internal links and the WebSocket address will not include the prefix, and pages, assets, and live updates will fail to load.

Single Sign-On and the Public URL

For a sub-path deployment, set the Public URL to include the context path (for example https://host.example.com/cosmo). If you use SAML or OIDC, also update the registered redirect / sign-out URLs at your identity provider to match — for example https://host.example.com/cosmo/login/oauth2/code/... or https://host.example.com/cosmo/logout/saml2/slo.


Verifying the setup

  1. Application loads. Browse to https://cosmo.example.com/ (or /cosmo/) and log in.
  2. WebSocket connects. Open the browser developer tools → Network → WS filter. You should see a …/stomp-endpoint/… connection that reaches 101 Switching Protocols and stays open. If it reconnects every few seconds, the proxy is buffering or timing out — revisit the buffering and timeout settings.
  3. Live updates work. Start a background job (for example a data import) and confirm the progress indicator updates in real time.
  4. HTTPS is preserved. After login, the address should stay https://. If it switches to http://, the X-Forwarded-Proto header is not reaching CosMO.
  5. Large uploads work. Upload a file close to 100 MB to confirm the proxy's body-size limit.

Common problems

Symptom Likely cause
Live updates stop; WebSocket reconnects every ~10–30s Response buffering on, or read timeout shorter than the heartbeat
WebSocket never reaches "101 Switching Protocols" Upgrade/Connection headers not forwarded (or WebSocket feature not installed in IIS)
Pages or assets return 404 under a sub-path Proxy strips the prefix, or context path not set in CosMO
Redirects or SSO go to http:// or the wrong host Missing X-Forwarded-Proto / X-Forwarded-Host
File upload fails with HTTP 413 Proxy request-body limit below 100 MB
SSO login loops or reports an invalid redirect URL Public URL not set, or identity-provider URLs not updated for the new path or host