Recently I am learning Go language for the distributed system course. Basically, golang is a programming language developed by Google – it has a C-like code style and an enhanced support for concurrency, which means writing a server with golang is a good idea.
Golang has an online version tutorial here. It has a server-based compiler and allow you to run some script. Since it is on a public server, its speed is somewhat slow. In this case, I planned to run the gotour on my own VPS.
I downloaded and started gotour on my VPS. However, when I saw an message told me to open a browser and type
http://127.0.0.1:3999, I realized that things could not be that easy. As expected, directly visit 3999 port will receive an instant HTTP error.
Leaving in China behind firewall for years, I instantly remind the SSH tunnel. By using SSH tunnel, you don’t need any extra software and you can access 3999 port as if you were localhost. By experiment, it did work but it was quite slow, which reminded me the days in China. After all, SSH is not designed for proxy.
I searched on Google but it seems that no one cares about that, and I had to figure out myself. By searching the source code, I find two places was related to localhost. Both in
httpListen = flag.String("http", "127.0.0.1:3999", "host:port to listen on")
openBrowser = flag.Bool("openbrowser", true, "open browser automatically")
(The other one is to display an warning message. I didn’t attempt to modified it)
Ah-hah! httpListen, a really easy-understanding name, right? Now change it to
0.0.0.0:3999. Don’t forget to type
go install to compile. Now, I got an warning message:
WARNING! WARNING! WARNING!
I appear to be listening on an address that is not localhost.
Anyone with access to this address and port will have access
to this machine as the user running gotour.
If you don't understand this message, hit Control-C to terminate this process.
Really look like an important notice, right? Okay, I admit that allowing others to run program on my server is not a good idea.
I opened my local web browser, successfully received the tutorial page. However, to my suppress, I couldn’t run any code, and got an error message like:
2016/01/** **:**:** bad websocket origin: http://****.***:3999