Strapi + NGINX + docker-compose without fixed URL

This is a question similar to this one. I’ve also read the documentation on Nginx Proxying

There are some key differences in my setup, hence the new thread. Here’s my setup:

docker-compose.yml:

services:
    nginx:
        (an NGINX reverse proxy)

    node:
        (an api backend)

    mongo:
       (a mongo db container)

    cms:
        (a strapi container)

nginx.conf:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /usr/share/nginx/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / { 
            try_files $uri $uri/ =404;
        }
    
        location /api {
            proxy_pass http://node:80;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_cache_bypass $http_upgrade;
            client_max_body_size 512M;
        }
    
        location /cms {
            proxy_pass http://cms:1337;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $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 Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_pass_request_headers on; 
        }
}

I need Strapi to be available at http://(any address):(any port)/cms

It seems it is generally encouraged to define a static URL in the config for Strapi to understand that it’s in a “subfolder”, but I can’t do that for this project. When running the setup above and go to http://my-app:my-port/cms, I just get a 404 Not found from the Strapi container.

How would I achieve this exact setup?

1 Like