Monday, July 20, 2015

Yaws - Install and Configure route

I have been looking to build a wiki based on things in my head. I then figured it would be fun to write some Erlang, and I'm a fan of Yaws - Yet Another Web Server - so I decided to install yaws, designate a subdomain to it, and have apache proxy requests to port 8080, where Yaws is listening.

Step One - Install Yaws

sudo apt-get install yaws

well that was easy.

Then you can check the status of the yaws service

To view the default yaws page, navigate to the url: (localhost:8080 if on the same machine - I'm installing on a raspberry pi over ssh, so I'm useing the static IP) as seen in the status, you can also navigate to https://<URL>:8443 and get the same

Step Two - Access Yaws by Domain Name

I'm running this on a chromebook and haven't yet found a way to change how chrome resolves hostnames. To get around this, I use dnsmasq on the pi to allow computers on my network to access the local site. I put 

in /etc/hosts and reload with sudo service dnsmasq force-reload to put the new domain into effect. This allows me to access the page through (or 8443 if using https). Before going any further, I've added the apache configurations from this post to a github repository

Step Three - Eliminate the Port

In order to eliminate the need for the port, I'd like to use apache to proxy and send any traffic destined for over port 80 (the default http port) to port 8080. I do this by setting up a virtual host in my apache configuration.

I found this article very helpful when configuring virtual hosts on my server. It explains that apache looks for and reads the configuration in conf.d/virtual.conf, as well as explaining how apache treats the sites-available and sites-enabled directories. It is clear enough from their names, but I like to know why programs do certain things. Instead of being explicitly configured in a file, anything in these directories is loaded on startup by apache.

The configurations for each <VirtualHost> is saved in sites-available, and a link is placed in sites-enabled using the a2ensite command (a2dissite will clean up the link).

And the debugging begins... 

At first, I had NameVirtualHost * defined in my virtual.conf file. This caused apache to complain about mixing http and https ports. I got around this by adding a second line, and changing the * in the two lines to *:80 and *:443.

I fumbled around for a while trying to reload via: service apache2 and contstantly getting the message:
[FAILED] Reloading web server config: apache2 failed! 

This stack exchange post addressed the issue, or rather pointed me to the command: `apachectl configtest` which told me that I had a syntax error in line 5 of my virtual host configuration - ProxyPass needed a source path, and I reloaded after inserting a '/ ' between ProxyPass and my forwarded URL. This enabled me to reload apache without issue.

One more test showed displaying the main apache page, but with one last command:
a2dissite default 

disabled the default virtual host, leaving my custom virtualhost for the yaws app to handle the request.

No comments:

Post a Comment