Change cockpit entrypoint url


#1

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


#2

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


#3

@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.


#4

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;
}
(...)