重定向URL路径到端口

I have many web apps running on a server. Some of them I have made, some of them are open source (such as open-cloud). All my web apps run on a specific port. My port 80 is still free.

I would like to make a nice welcome web page to all my apps on the port 80 to allow my co-worker to see them on the local network.

My problem is to setup the urls map. I would like the path http://machine-name:80/open-cloud/ to be the exact same thing then http://machine-name:8080/ (including the static files if possible).

One other possible solution would be to use sub-domaines such as http://open-cloud.machine-name:80/ for each application. But I do not know how to do that inside a local network.

I am looking for a solution in Python, node.js or Go (that would be awesome!). It is important to notice that none of my web app runs on ssl and that it will probably handle very low trafic. It is only a local network after all!

Any help and reference would be welcome.

Cheers!

You just need some kind of proxy, like http://nginx.org for example.

Then pass the domains you want to your application ports:

server {
  listen 80;
  server_name app1.local;

  location / {
    proxy_pass          http://127.0.0.1:8080/;
    proxy_set_header    HOST $http_host;
    proxy_set_header    X-Real-IP $remote_addr;
  }
}

If you insist on writing your own solution in Go, you could setup a http.Redirect for each URL like this:

import "net/http"

var urlMap = map[string]string {
    "open-cloud": "http://machine-name:8080/",
    "some-other": "http://machine-name:9090/",
}

func redirectHandler(target string) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        http.Redirect(w, r, target, 301)
    }
}

func main() {
    for key, target := range urlMap {
        http.HandleFunc("/" + key, redirectHandler(target))
    }

    http.ListenAndServe(":80", nil)
}

However, I would rather rely on a tool like nginx as joewhite86 already proposed.