Problem with Ajax errors, CORS and port forwarding

Hi,

I’m looking for a bit of advice. I have LibreNMS set up and running on a small server. I also have a valid SSL certificate set up on it too. The server sits inside my network on a private IP address (let’s call it 192.168.1.1).

So to access the server from inside the network, I’m using https://192.168.1.1 - this works just fine bound to port 443.

However, I’d like to punch a port forwarding setup from my router to the server to allow me to access it via the Internet. When I do that, and try to access it via https://server.foobar.com:8443 I get a bunch of browser access warnings

[Error] Unhandled Promise Rejection: SecurityError: Script origin does not match the registering client’s origin
[Error] Origin https://server.foobar.com:8443 is not allowed by Access-Control-Allow-Origin.
[Error] XMLHttpRequest cannot load https://server.foobar.com/ajax_form.php due to access control checks.

Okay - so this sounds like I need to enable CORS to allow access. However, I can’t seem to get this to work at all. The $config[] examples for CORS all seem applicable to API access from external hosts (and don’t help me here when configured)

I’ve had a look at and tweaked config/cors.php to enable CORS there for this

‘allowed_origins’ => [’*’],

but that doesn’t seem to help either.

So to recap - I want to be able to access LibreNMS from https://192.168.1.1 and https://server.foobar.com:8443 but can’t get the latter option to work. Help? Anyone done this and can offer words of wisdom as to how I get LibreNMS to generate the right CORS preflight response for me?

Thanks!

Scott…

Sounds like you have lnms config:get base_url set to your internal IP, try setting it to lnms config:set base_url /

Ah. Thanks for this - simplest solutions are the best. :slightly_smiling_face: I managed to wipe the base_url setting out and that fixed the problem. Thanks!

Scott…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.