8 Replies Latest reply on May 31, 2016 11:36 AM by fserre RSS
    fserre Explorer

    How to set up a reverse proxy with organization structure?

    I am trying to put in place nginx as a reverse proxy to hide the thingworx's URLs.

    I use this configuration for nginx:

        server {

            listen       80;

            server_name  localhost;


              location /MyApp {

                   proxy_pass http://localhost:8080/Thingworx/FormLogin/MyAppOrg;

                   proxy_set_header Host $host;

                   proxy_set_header X-Real-IP $remote_addr;

              }

         }

    It works fine for the login page of the organization but the Home Mashup cannot be displayed, I got an 404 error.

    To solve it, I need to add this rule:

              location /Thingworx {

                   proxy_pass http://localhost:8080/Thingworx;

                   proxy_set_header Host $host;

                   proxy_set_header X-Real-IP $remote_addr;

              }

    But by doing this I didn't mask anything, I can see the full internal url in the address bar after logging...

     

    Does anyone know how to setup a reverse proxy with organizations ?

      • Re: How to set up a reverse proxy with organization structure?
        aanjan Heavyweight Champ

        Fabien, can you post your .conf file? With your location set as /Thingworx, all the proxy_pass flag would need is host:port.

          • Re: How to set up a reverse proxy with organization structure?
            fserre Explorer

            Thanks AAnjan for your answer. I've modified the .conf file as followed:

             

            worker_processes  1;

             

            events {

                worker_connections  1024;

            }

             

            http {

                include       mime.types;

                default_type  application/octet-stream;

             

                sendfile        on;

                keepalive_timeout  65;

             

                server {

                    listen       80;

                    server_name  localhost;

             

                    location /Thingworx {

                           proxy_pass http://localhost:8080;

                           proxy_set_header Host $host;

                           proxy_set_header X-Real-IP $remote_addr;

                      }         

                      location /MyApp {

                           proxy_pass http://localhost:8080/Thingworx/FormLogin/MyAppOrg;

                           proxy_set_header Host $host;

                           proxy_set_header X-Real-IP $remote_addr;

                      }

                 }

            }

             

            But once logged, I am still redirected to : http://192.168.73.128/Thingworx/Runtime/index.html#master=MyAppMain&mashup=WelcomeScreen

              • Re: How to set up a reverse proxy with organization structure?
                aanjan Heavyweight Champ

                Since you have the location for /Thingworx, can you remove the /MyApp one and retry? So that your server section would just have location /Thingworx.

                 

                Here's an example configuration I've used before:

                 

                server {

                    listen      80;

                    server_name  localhost;

                 

                        location /Thingworx/WS {

                            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                            proxy_pass http://thingworx_server;

                            proxy_http_version 1.1;

                            proxy_set_header Upgrade $http_upgrade;

                            proxy_set_header Connection "upgrade";

                            include /etc/nginx/conf.d/acl.default;

                            allow a specific ip;

                            allow 127.0.0.1;

                            deny all;

                        }

                 

                        location / {

                            add_header Access-Control-Allow-Origin *;

                            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                            proxy_pass http://thingworx_server;

                            proxy_http_version 1.1;

                            include /etc/nginx/conf.d/acl.default;

                            allow a specific ip;

                            allow 127.0.0.1;

                            deny all;

                        }

                 

                I've added the upgrade headers to allow EMS websocket connections as well. My setting was was specific to allow any connection that would hit /Thingworx/WS (primarily used for Edge connectivity).

                  • Re: How to set up a reverse proxy with organization structure?
                    fserre Explorer

                    Sorry Aanjan, I am confused. If I keep only the /Thingworx location, I will redirect all requests from /Thingworx to my proxy_pass.

                    What I really want to do is to replace all Thingworx words within the URL by my own application name.

                    I can put a reverse proxy for one direct request like an API call or my login organisation page. It works fine, thingworx references is removed.

                    But when the user logs in, the platform calls an URL like this: myServer/Thingworx/Runtime/index.html.

                    And the browser address bar shows the full URL.

                    I read in previous posts that the solution to remove "thingworx" reference within the URL is to use a reverse proxy. But I am perhaps wrong...