mark down pastes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

6.6 KiB

Setting up a Home Server

Launching the server application on your computer

  • Most server applications do not come with graphical user interfaces -- but they DO output logs describing how they are doing, if they started up properly or not, etc. So you will probably want to run the server application from the terminal in order to see its log output.
  • Some server applications you could try for a quick test: nginx, create-react-app (requires node.js), or the http.server module that is built into python.
  • Server applications have to open a listening port in order to function. Operating systems restrict the ability to open port numbers less than 1000 unless the requesting program is running under an "administrator" user. So watch out for that. Normally, test servers are set up to run on ports like 3000, 5000, 8000, or 8080.
  • Once the server application is running, you should be able to connect to it by typing localhost:<portnumber> into your web browser's URL bar and navigating to it.
    • For example, like localhost:3000 or localhost:8080.

Making your computer accessible on the internet, so internet users around the globe can connect to it

  • Computers connected to "end-user" networks cannot be directly dialed (connected to) from the outside world.
  • The router for the network usually can be directly dialed, however.
  • You will have to be able to log into the administration panel of your router. Most routers have instructions on how to do this printed on them somewhere, or at very least they should have the default username and password for the admin user printed on them.
  • You can usually find the IP address of your router by asking the operating system.
    • MacOS:
      • Preferences > Network > TCP/IP where it says "Router"
      • OR: Run in Terminal: netstat -nr | grep default
    • Windows:
      • run in cmd.exe: ipconfig
      • scroll down to where it says "Default Gateway. . . "
  • Once you have found the routers IP address and its username and password, you should be able to log into it. Simply type the router's IP address into the address bar of your web browser and navigate to it.
    • You should land at the login page for the router administration panel, here is an example of what this looks like for a centurylink router:
  • Next you will have to obtain the IP address of your computer on the LAN (local area network) that the router creates.
    • MacOS:
      • Preferences > Network > TCP/IP where it says "IP Address"
      • OR: Run in Terminal: ifconfig | grep inet
    • Windows
      • Run in cmd.exe: ipconfig
      • scroll down to where it says "IPv4 Address. . ."
  • Almost all routers have a feature called "port forwarding". You will want to navigate to that feature and create a port forwarding rule for the port that your server application is listening on, and the LAN IP address of the computer running the server application.
  • Last step, we need to test it. First, we need to know what your router's Public IP address is. The easiest way to figure this out would be to use a service like https://www.whatismyip.com
  • You may or may not be able to access your server right now by copy and pasting the public IP address into your browser's address bar. (And appending the appropriate port number, for example, 12.23.80.231:8080).
  • Some routers do not properly handle this "route-to-the-public-version-of-myself" request. So to get a reliable test, you may have to ask someone on a different network to test it for you, turn on your VPN, use your mobile phone's 3G/4G/5G connection to test it, or in a pinch, try hitting it from a sketchy "free unblock me" style web proxy.

Setting up a Domain Name for your server

  • You can pay about $10 a year to register a real domain name from a provider. My favorites are gandi.net or namecheap.com.
  • For a quick test you can use a free provider like freedns.afraid.org
  • Once you get the account set up with your provider of choice and get the domain registered, you will want to create an "A Record" for the domain having your router's public IP address as the value for the record.
  • DNS can take anywhere from half a second to 24 hours to "propagate". So if you can't reach your server at your domain name right away, don't panic, and don't start changing things willy-nilly.
  • Try resolving the domain name manually to see if it has propagated to you yet.
    • For a quick test you can use a web-based free service like https://www.whatsmydns.net
    • There are also command line tools to do this like nslookup and dig.
  • Finally, you should be able to type your domain name and appropriate port into the web browser's address bar and see your website. For example:
    • my-domain.com:8080

Setting up TLS/HTTPS with a free certificate from Let's Encrypt

  • This is a bit more of an advanced topic, but luckily there are plenty of tools that make this easier. Let's Encrypt developed two great tools to make it easier, one of them is called certbot, and the other one is called Caddy.
  • certbot is a python script that you have to manually invoke to generate certificates.
    • make sure to turn off your web server application before you run Certbot, as Certbot may need to listen on the same port that your web server is already listening on.
  • Caddy IS a web server application and it automatically generates certificates for you, as long as your Router and DNS are already set up correctly. You can also configure Caddy to forward to another web server on your computer. This is called "reverse proxy".