Setting Up Apache Server on a Raspberry Pi 3

Setting up Port Forwarding

Your browser needs to be JavaScript capable to view this video

Try reloading this page, or reviewing your browser settings

Covers the essentials to opening ports on a router and setting up Apache to listen for web requests on those ports. Every router is different, so keep in mind that the port forwarding process may vary across different routers.

Keywords

  • virtural servers
  • NAT forwarding
  • port forwarding
  • ip address
  • routers
  • internet
  • Apache
  • Apache server port
  • port 80 blocked
  • HTTP port

About this video

Author(s)
Braxton VanGundy
First online
19 March 2020
DOI
https://doi.org/10.1007/978-1-4842-5848-4_5
Online ISBN
978-1-4842-5848-4
Publisher
Apress
Copyright information
© Braxton VanGundy 2020

Video Transcript

Right now, the Apache web server is only accessible through your local network. No one outside your network is going to be able to access your site hosted on Apache. In order to allow others to access the website on your Pi, you’re going to have to set up port forwarding on your router. From a high-level perspective, in short, port forwarding routes a request from outside your network to a device inside your network via an identifier tacked onto your network’s IP address called a port number.

Now the default HTTP port is port 80. This is the port that you should be using to direct traffic to your Raspberry Pi server. However, most consumer internet service providers block access to this port. So the only way around that is to use a non-standard port for HTTP requests. Before I show you how to set up port forwarding, here are just a couple of things you should keep in mind.

First off, hosting a web server may violate some internet service providers’ policies. So read up on your ISP terms of service before you set up a public-facing server on your home’s network. Secondly, by opening ports and directing traffic to the Pi, you are further exposing your home’s network to the dangers of the world wide web. So proceed at your own risk.

Finally, the process of port forwarding varies across routers. What I do here is going to be similar, but not identical to what you are going to have to do to set up port forwarding on your router unless you have the exact same router that I do. But I doubt that’s the case.

Remember when I told you to take note of your gateway address earlier? This is where you’re going to need it. Type your gateway address into your web browser to access your router’s web portal, enter your credentials, and go to the not forwarding settings for your router. This section is also commonly called port forwarding or port triggering across different routers. Once again, if you have a different rather than I have– and chances are, you do have a different router– some of this you’re going to have to figure out on your own because every router is a little bit different.

Now I’m going to create a new entry for port forwarding, and this is done under virtual servers for my router. Pick a port that is not in use. Two good options are either port 100 or port 112, but you can find a whole list of unused ports online. As you can see, I’m using port 112.

Set the internal port to the same port number as the external port. The service type field is just the name identifier and can be set to whatever memorable name you want. We are going to route this port to the internal IP address of our Raspberry Pi. So in the internal IP field, enter the IP address of your Raspberry Pi.

Finally, set the protocol field to all and save the virtual server entry. Now we need to make a quick change to the Apache ports configuration file to tell it to listen to the port just specified, in this case, port 112. Use CD to navigate to etc/Apache 2. Find the ports configuration file and enter sudo nano ports.conf to edit the file.

Under the line listen 80, add another line to tell Apache 2 also listen on port 112. Save the changes to the file and exit nano. Restart the Apache server using the sudo service Apache 2 restart command. The changes will take effect following the restart.

Google your home network’s IP address and enter this address into a phone connected to an LTE network to make sure your server is accessible to an outside network. If you can access the site through your phone, you have set up port forwarding correctly. Your server is now accessible from anywhere in the world.