How to setup a reverse proxy server with nginx, Raspian Jessie Lite and Raspberry Pi 3

If you plan to deploy multiple devices at home and made them publicly accessible from outside your home network, you may want to consider setting up a reverse proxy server that will route HTTP traffic from the internet to the respective devices residing in your home network.

Tagged with an affordable price tag with good specifications, the Raspberry Pi 3 is an ideal candidate for the hardware of a reverse proxy server at home. And since the nginx server is a powerful reverse proxy server that can run efficiently on commodity hardware, it is an ideal candidate for the software aspect of a reverse proxy server.

This post documents how to setup a reverse proxy server with nginx, Raspian Jessie Lite and Raspberry Pi 3.

Hardware recommendations for the reverse proxy server

I recommend the following hardware for the reverse proxy server:

If you had a spare micro USB charger that came along with your typical Android phone, you can use it to power your Raspberry Pi 3 instead of buying the CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / Adapter / Charger (UL Listed).

Prerequisite hardware to install operating system onto the microSD

Raspberry Pi 3 board will load an operating system from a microSD card. Hence, we will need to have a computer with a SD card reader. If your computer does not come with a SD card reader, you have to get one.

If you have the standard SD card reader on your computer but do not have a SD card adapter, you may want to get the Kingston Digital 32 GB microSDHC Class 10 UHS-1 Memory Card 30MB/s with Adapter (SDC10/32GB) instead.

Getting a copy of Raspbian Lite

Once we had gotten the hardware, we can then proceed to download a copy of Raspbian Jessie Lite. The latest Raspbian operating system is available at https://www.raspberrypi.org/downloads/raspbian/. As of this writing, the one that was available was "RASPBIAN JESSIE LITE":

2017-07-13 Raspbian download page

Click on the Download ZIP button and save the file onto your file system.

Installing Raspbian Lite on the microSD card

Once you had gotten the .zip file in your computer, extract the .img file from the .zip file. The .img file is the operating system image that we will use for installing Raspbian Jessie Lite onto the microSD card.

If you have a MacBook, you can use Etcher to install the operating system image onto your microSD card.

If you are using a windows machine, you can use Win32DiskImager to install the operating system for your Raspberry Pi 3.

If you are using a Linux desktop, you should be able to Etcher to install the operating system for your Raspberry Pi 3.

Enabling SSH server for accessing your Raspberry Pi 3 without connecting a keyboard and monitor to it

With an SSH server running on Raspbian Jessie Lite, we do not have to find a spare keyboard and monitor in order to configure Raspbian Jessie Lite after it had booted up for the first time. To ensure that we have the SSH server running after the first boot, we can create a file named "ssh” in the boot partition of the SD card:

Raspbian Jessie Lite 20170705 boot with ssh file

Assembling the reverse proxy server hardware

Once you have installed Raspbian Jessie Lite onto your microSD card, remove your microSD card from your SD card reader and insert it to the SD card slot on the Raspberry Pi 3 board. After that, proceed to assemble the Raspberry Pi 3 board to the Official Raspberry Pi case.

Booting up your Raspbian Lite operating system

With the assembly of your Raspberry Pi 3 board and Official Raspberry Pi case, you need to connect one end of the RJ45 cable to the RJ45 port on your Raspberry Pi 3 board and the other end of the cable to one of the switch port of your home router. After that, plugin your micro USB cable and supply power to your Raspberry Pi 3 board.

Finding the IP address of your Raspberry Pi 3

When Raspbian Jessie Lite boots up, it will request an IP address from your router. We will need this IP address in order to SSH into the Raspberry Pi 3. Go to your router's address allocation table and find an entry with the name raspberrypi. Note that IP address for SSH access.

SSH into your Rasbian Jessie Lite with the default credentials

With the IP address, we can then SSH into our Raspberry Pi 3. Assuming that the router had given our Raspberry Pi 3 the IP address 192.168.0.123, we will then open up a terminal program and enter the following command:

ssh pi@192.168.0.123

The default password for the default user pi is raspberry. Enter raspberry when the ssh command prompts for a password and we will be able to get into our Raspbian Jessie Lite to perform other configurations.

After logging into your Raspbian Jessie Lite successfully, you will be able to see the following output:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

Changing the default password for user pi

As hinted by the server output, we should change the default password for the pi user. To do so, we enter the following command into the terminal after we had logged into Raspbian Jessie Lite as the pi user:

passwd

At the prompt, type in raspberry for (current) UNIX password and your favourite password for the next two prompts.

Configuring the locale settings

Once we have changed the password, we should configure the locale settings too.

To do so, we first run the Raspberry Pi Software Configuration Tool:

sudo raspi-config

And use it to generate the "en_US.UTF-8" locale and set it as the default locale for the system environment:

raspi-config Raspbian Jessie Lite with Localisation Options selected

raspi-config Raspbian Jessie Lite with Localisation Options -> Change Locale selected

raspi-config Raspbian Jessie Lite screen for generating en_us-UTF-8 locale

raspi-config Raspbian Jessie Lite settings en_us-UTF-8 as default locale for system environment

After doing so, open up /etc/default/locale with nano:

sudo nano /etc/default/locale

And updated the contents to look like the following:

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANGUAGE=en_US.UTF-8

This will ensure that the locale setting persist through system reboots.

Installing nginx on your Raspbian Jessie Lite operating system

Once we had configured the locale settings, we can then proceed to install nginx. To install nginx on Raspbian, we can enter the following command:

sudo apt-get update
sudo apt-get install nginx -y --fix-missing

Once the command completed running, we will be able to use our browser to communicate with nginx:

accessing nginx after installation on Raspbian Jessie Lite

Examples of using nginx as a reverse proxy server at home

Once we have nginx running on Raspbian Jessie Lite, we can use it as a reverse proxy server at home. The following is a list of articles which contain examples on how we can use nginx as a reverse proxy server at home:

Buying the recommended hardware list to setup your own reverse proxy server with nginx, Raspian Jessie Lite and Raspberry Pi 3

If you do not have the Raspberry Pi 3 hardware mentioned in this post yet, you may want to purchase them from Amazon. Simply click on the button below to add the Raspberry Pi 3 hardware to your cart. You may remove anything that you already have or replace some of the hardware with other hardware.


About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.