Archive for 2015

Apache httpd: Default Virtual Host


I have several virtual host configuration in my httpd.conf. Today i need to one of it can be accessible in a local wifi network. I knew it will require a DNS configuration pointed my IP address to a domain name on the router. But unfortunately I have no access to the router.

Second choice is directly point my IP address in any client hosts file who want to access my virtual host. But it will be painful due to my IP address was  configured dynamically by router DHCP server, what if it change? I have to edit all client host file again? No thanks.

Based on this Apache httpd documentation, first VirtualHost block in the configuration file has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by the first VirtualHost. Finally I use this last option, all I have to do is put desired virtual host block to the first block, then all host in my local wifi network can access it with my current IP address.

* image from : www.thetechnicalstuff.com

Golang: Web Deployment Experience


I've finished building a web based application with golang. The last step is deploy that app to the production server. In this post I want to share how to deploy golang code, especially a web based application.

There are at least 3 ways to deploy golang code. Firstly, deploy source code and run it directly. This is the safest way to deploy because if there is any unsatisfied dependency, go run will complain. You can use watcher tool like gin with this way, it will watch on code changes and do live reload. 

Second, deploy the source code and run binary resulted by go build. This way is not really different than first way, but you cannot use any available watcher tool. Because you run the binary file. The third is deploy only binary file. Wait, what if the target architecture is different? Golang has multi os and architecture build parameter which are GOOS and GOARCH. You can specify them with your target requirement.

In my opinion, deploying only a binary file is the most efficient way. Golang build tool go build was smart enough to build a binary file with no dependency. Except, you, by accident, need C binding and hard to make it statically linked like in my circumstance. I used combination between second and third way. I deployed source code to staging server then build a binary file. I deployed that binary file to production server. In my circumstance, I develop in OS X and using library that bind C with CGO. Both my staging and production server are Centos. GOOS and GOARCH are not friendly with CGO. I choose to build in staging server and deploy that binary to production server.

*image from l-lin.github.io