Making a static NGINX page
This tutorial will walk you through installing NGINX and creating a static page on Linux.
NGINX, pronounced “Engine-X”, is among other things an open-source web server. It was originally written by Igor Sysoev and released under the 2-clause BSD License.
Installing NGINX
Use your distribution’s package manager to install the nginx package:
sudo apt install nginx
sudo pacman -S nginx
sudo dnf install nginxIf all goes well, you should have successfully installed NGINX to your machine.
Configuring NGINX
In /etc/nginx/sites-enabled/default, you will find the default NGINX configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}This might look complicated, but we’ll walk you through it. The first part after the server block sets the port on which your page will be served. By default, this is the standard HTTP port, 80.
After that, the root of the site is declared. This is the folder in which your files that you want to serve should be.
In this case, it’s /var/www/html, where a placeholder NGINX html file is.
The next part says which files NGINX should look for as index files, the file that will be displayed when visiting the ‘homepage’ of your site.
You can see that index.nginx-debian.html is a file that NGINX should look for and serve. This is also the file you will see when visiting your site
as long as you haven’t changed it.
The rest of the default configuration is not important for now. Let’s focus on making your site.
Creating a static page
Assuming you want to keep using port 80, we can close the NGINX config and head over to /var/www/html:
cd /var/www/htmlTo visit your site, you need the IP address of your machine.
ip aIn your browser, you can type in just the IP address and no other port, as port 80 is a standard HTTP port.
You should see a page congratulating you on installing NGINX. But this might not be what you want to show people. So, let’s remove this file:
rm index.nginx-debian.htmlWe can make a new index file:
nano index.htmlNow, we can start writing your static page. Let’s say you want to state your name and job.
<p>Hello, I'm Noa. I write articles at HowToLinux.</p>You can change this however you like. When you’re done, exit nano with CTRL+S and CTRL+X.
To be sure NGINX will serve your new page, reload it:
sudo systemctl restart nginxOn your site, you should now see your formatted text from index.html.
Congrats, you’ve made a static page with NGINX!