Create Your Own Linux-Server With Nginx for Beginners With IP-Public
Why create a server at home?
I have been trying several hosting and in the end, all of them have the same limitations, on one hand the price and on the other hand the computer capacity.
That’s why I decided to set up my own web server so as not to depend on third parties.
- Internet connection with IP-Public or IP-Fixed(I don’t think your provider will give it to you)
- PC or Laptop with Ubuntu 20.04(do not use raspberry, it has limitations when installing python libraries), I recommend 128gb of disk, 8gb of ram and very quite fans.
Get down to it
First you have to make sure you have a public ip.
With this commands you can verify it:
- to find out your ip
curl -4 icanhazip.com
- to find out the trace
traceroute -I 220.127.116.11
If the trace has 1 single hop, it means you have public IP, if it has 2 hops it means you are in CG-NAT.
If you are within CG-NAT, in my case it was as easy as calling my internet provider and telling them to switch me to public ip, most providers have no objection to switching you to public ip at no extra cost.
It is important to open ports 80 and 443 for your server to connect to the outside.
In my case the router is accessed through 192.168.1.1, and you have to configure port forwarding in the control panel with the internal IP or your server.
Convert the public ip into a fixed dns with DuckDns
The function of a dynamic DNS service is to facilitate access to a server that has a dynamic public IP.
Therefore, when this public ip changes it will not be important because you will have a DNS that automatically has the public ip of your server updated.
We will access the following URL:
Once inside the URL we will create an account from our Google account, reddit, Github or Twitter. In my case I generate the account using my gmail account.
To create the domain example1.duckdns.org we only have to write example1 in the section domains and then press the button add domain. The domain will be generated automatically.
Now follow the instructions in install for linux cron and you will have your dns fixed.
Now your fixed dns that updates with your public ip every 5 min will be:
Let’s install nginx
nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.
sudo apt install nginx
List the application settings that UFW knows how to work with by typing in the following:
sudo ufw app list
You should get a list of the application profiles:
As shown in the result, there are three profiles available for Nginx:
- Nginx Full: this profile opens port 80 (normal, unencrypted web traffic) and port 443 (encrypted TLS/SSL traffic)
- Nginx HTTP: this profile opens only port 80 (normal web traffic, not encrypted)
- Nginx HTTPS: this profile opens only port 443 (encrypted TLS/SSL traffic)
Now we have to enable the FULL profile:
sudo ufw allow 'Nginx Full'
You can verify the change by writing the following:
sudo ufw status
The result will indicate the FULL traffic that is allowed:
Checking that everything works
At the end of the installation process, Ubuntu 20.04 starts Nginx. The web server should already be active.
Check with systemd init to make sure the service is running by typing the following:
sudo systemctl status nginx
As confirmed by this result, the service was initiated correctly. However, the best way to check this is to request an Nginx page.
You can use your public ip or example1.duckdns.org that you configured with DuckDns, enter it in the address bar of your browser:
You should get the Nginx landing page as a result:
Note: try it with a different connection than the one the server is connected to, for example with the 4g of your mobile phone.
If you are on this page, your server is running correctly and is ready to be managed.
In the following article, I will tell you how to host in this server an interactive dashboard created in python with dash-plotly.
Thanks for reading this post, I hope this information will help you to advance your career or learn something new.
Check out my others Mediums: