The openHAB Raspberry image, by default, listens on port 8080. After using the image for a while, it became quite boring to always add the port to the URL. Quickly I decided to redirect port 80
to port 8080
, and make my life easier.
Not sure how much work that is in the openHAB settings, I settled with redirecting or forwarding the port 80
to port 8080
.
There are a few options: use a proxy, install a full flavored webserver and use that as a proxy, use a tool which generates a 301
or 302
redirect on port 80
, or use a tool which redirects the traffic itself.
The small utility redir
seemed like a good start, and the operating system already has a package for that. All I have to do is install the package, and create a service file for systemd sigh.
Let’s start with the package installation: that’s an easy task using Ansible. I decided to move everything into a separate role named redir
, this way I can just pull in the role. The directory structure looks like this:
|
|
The tasks
directory holds a main.yml
file which has all required installation instructions. The templates
directory has the template for the service file: redir.service
. The main.yml file:
|
|
Three steps:
- Install the
redir
package - Copy the template file to the remote host, into the
systemd
service directory - Restart the service, in case something changed
And finally, the service file:
|
|
The service itself is started using this line:
|
|
This tells redir
to redirect all traffic from port 80
to port 8080
. Because the port 80
is a privileged port, the service must be started as root.
Now all I have to do is adding the role in my main Playbook:
|
|