question

Mischa Spelt avatar image
0 Likes"
Mischa Spelt asked Mischa Spelt commented

Webserver not working behind prefixed proxy

Hi,

I was looking into using nginx as a reverse proxy for the FlexSim HTTP web server and ran into an issue when using path prefixes. I have nginx listening on port 443 and the FlexSim web server on port 4200, so the relevant part of my nginx config looks like this:

  server {
    listen       443 ssl;
    server_name  example.com
    <snip> # server_name and ssl_ configuration here
    location /model/ {
      proxy_pass      http://127.0.0.1:4200/;
    }
  }

So the idea is that going to https://example.com/model should show the FlexSim server... and that works! Almost! I get the interface and I can start an instance:

1675761344155.png

But when I try to connect to the instance I get a 404 not found. The problem seems to be that somewhere in the internals of the webserver, it constructs an incorrect path:

1675761424517.pngIt tries to load

/model/webserver.dll/queryinstance=tutorials\FlexSim 2023\StatisticsCollectorTutorialModel&instancenum=1/?defaultpage&dashboardstats=1&time=1675761445901

but that gives a 404 Not Found error.

I guess one solution is: then don't use the reverse proxy... but this feels like I should be able to get it to work but it's just a small bug... right? :-)

FlexSim 23.0.3
webservernginx
1675761344155.png (37.1 KiB)
1675761424517.png (36.3 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jacob Gillespie avatar image
0 Likes"
Jacob Gillespie answered Mischa Spelt commented

That configuration looks good. I just tried it myself and it was going to /model on the other side of the proxy until I put a / on the end (ie http://127.0.0.1:4200/ ).

Maybe try restarting the daemon?

· 6
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image Mischa Spelt commented ·
Hi Jacob. So when you start an instance and then try to connect to it, you are seeing the model 3D view and controls, instead of a 404 error?
0 Likes 0 ·
Jacob Gillespie avatar image Jacob Gillespie ♦ Mischa Spelt commented ·

I just noticed that websockets needs to be accounted for too. Here is how to get them working:

location /model/ {
    rewrite ^ $request_uri;
    rewrite ^/model(/.*) $1 break;
    return 400;
    proxy_pass http://127.0.0.1:8080$uri;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
1 Like 1 ·
Jeanette F avatar image Jeanette F ♦♦ Jacob Gillespie ♦ commented ·

Hello @Mischa Spelt,

Did @Jacob Gillespie's comment help solve your issue?

0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt Jacob Gillespie ♦ commented ·
Sorry, I missed your reply earlier.

Everything seems to work now, thanks!

(I saw the documentation has a section on configuring the web server with IIS, perhaps it's also good to add a bit about nginx with the above code sample included).


0 Likes 0 ·
Jacob Gillespie avatar image Jacob Gillespie ♦ Mischa Spelt commented ·

@Mischa Spelt

Ok I figured out it was that you are trying to open a model in the tutorials sub-directory. Nginx is automatically unencoding the back slashes of the model path.

To fix this, see this stack overflow answer: https://stackoverflow.com/a/37584637

And here is the configuration I used to get it working:

location /model/ {
    rewrite ^ $request_uri;
    rewrite ^/model(/.*) $1 break;
    return 400;
    proxy_pass http://127.0.0.1:4200$uri;
}
0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt Jacob Gillespie ♦ commented ·

Thanks @Jacob Gillespie that already brings me a step further. It now at least loads the page with the top bar (back button, model name, instance no. etc) but the iframe is showing

Error: ENOENT: no such file or directory, stat 'C:\Program Files\FlexSim 2023\program\flexsimweb\?defaultpage'


0 Likes 0 ·