Search code examples
httpgohttpsbeego

Forward server API to another port using Beego


I have two web apps running in the same virtual machine. One is Beego listening to port 443, and another is Centrifugo messaging server at port 8000.

If a user is not allowed to connect port 8000 due to his ISP, is it possible that I forward https://my.domain/chat_api (intercepted by Beego at port 443) to https://my.domain:8000/chat_api (served by Centrifugo at port 8000), so that my chat client connects port 443 just like connecting port 8000? If yes, how do I implement under Beego's structure?


Solution

  • You dont need to implement this in Beego.

    Just set up a reverse proxy: (here is an example how to set up a reverse proxy with nginx)

    server {
       listen 443;
       server_name example.com;
    
       location /chat_api {
          proxy_set_header   X-Forwarded-For $remote_addr;
          proxy_set_header   Host $http_host;
          proxy_pass         "http://127.0.0.1:8000";
       }
       location /beego {
          proxy_set_header   X-Forwarded-For $remote_addr;
          proxy_set_header   Host $http_host;
          proxy_pass         "http://127.0.0.1:8080";
       }
    }