Change cockpit entrypoint url

Hello,

I’m trying to host cockpit and a node.js server on the same production server. I’m using Nginx to dispatch the access to the two servers based on the requested url.

The idea is that for any url I’d want to forward the traffic to the node.js server exposed on localhost:3000.
Instead I’d like to forward all the urls starting with ‘cms’ or ‘cockpit’ or any other differentiator to cockpit cms exposed on localhost:8080.

So I’m trying a way to change the cockpit entry point for all its paths. For example:
localhost:8080/auth/login should be localhost:8080/cockpit/auth/login
localhost:8080/collections should be localhost:8080/cockpit/collections

in this way I can tell Nginx to forward any traffic to cockpit cms based on if the url starts with cockpit.

Is there a way to do it?
Thank you

I’m trying to reverse proxy cockpit cms that run with Docker.

In the official documentation I found (https://getcockpit.com/documentation/reference/configuration) that I can change the site url:

 # site url (optional) - helpful if you're behind a reverse proxy
'site_url' => 'https://mydomain.com',

But it doesn’t really work.

I also tried to edit the define.php file adding some definitions:
define(‘COCKPIT_BASE_URL’, ‘/admin’);
define(‘COCKPIT_BASE_ROUTE’, ‘/admin’);
define(‘COCKPIT_DOCS_ROOT’, “/var/www/html”);

I got to have cockpit forward itself to admin/… but some routes don’t work yet.

Thank you

@alessandro If you try to understand the paths and constants, have a look here:

I’m not sure, how to achieve the forwarding, but maybe… it could be easy… Put Cockpit in a subdirectory named cockpit → now your url is localhost:8080/cockpit/auth/login

Or add a line to the .htaccess to rewrite some specific urls.

And you started a second thread

Have a look at index.php of Cockpit:

Maybe this might work: define the constant COCKPIT_ADMIN_ROUTE in /config/bootstrap.php to your needs.

Hey @alessandro, think issue is not on cockpit but on nginx configuration, basically what you need is:

https://domain.abc/cockpit => http://localhost:8080

(...)
location /cockpit {
    proxy_pass http://127.0.0.1:8080;
    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;
}
(...)

This worked for me on Docker setup by modifying defines.php, some of assets are still generated with wrong path, because of that settings are infinitely loading.
<?php
define(“COCKPIT_BASE_URL”, “/cms”);
define(“COCKPIT_BASE_ROUTE”, “/cms”);
define(“COCKPIT_DOCS_ROOT”, “/var/www/html”);
define(“COCKPIT_SITE_DIR”, “/var/www/html”);
?>

I think it would be great to have something like ROOT_URL or URL_PREFIX in cockpit config.php file which would add url prefix for all of the routes simplifying reverse proxy setup.

One of the workarounds would be to use sobdomains on nginx instead of folders.

UPDATE

codemirror.js file is getting included in script tag as /cms/assets/…/codemirror.js it causes the issue.

Did you tried it ? This is not working, it is redirecting to /auth/login on nginx which doesn’t have this location defined. Url prefix should be set from cockpit side.