3.1 KiB
To serve your index.html file using Nginx on Arch Linux, you need to follow a few simple steps for installation, configuration, and starting the web server. This guide is meant to help you get started.
Step 1: Installing Nginx
-
Open your Terminal.
-
Update your system package database by running:
sudo pacman -Syu -
Install Nginx with the following command:
sudo pacman -S nginx
Step 2: Configuring Nginx to Serve Your HTML File
-
Navigate to the Nginx configuration directory:
cd /etc/nginx -
The main configuration file is
/etc/nginx/nginx.conf, but for hosting specific sites, it's a good practice to use thesites-availableandsites-enabledstructure, which might not be set up by default on Arch. Let's create those directories:sudo mkdir sites-available sudo mkdir sites-enabled -
Add the following line to the bottom of the
nginx.conffile to include thesites-enableddirectory. You can open it with your favorite text editor, for example:sudo nano nginx.confAt the bottom of the file, add:
include /etc/nginx/sites-enabled/*;Then save and close the file.
-
Create a new configuration file for your site in the
sites-availabledirectory. Replaceyourdomain.comwith your domain name orlocalhostif you don’t have one:sudo nano sites-available/yourdomain.com -
Add the following server block (adjust the
server_nameif using a domain, and change/path/to/your/index.htmlto the actual path of yourindex.htmlfile):server { listen 80; server_name yourdomain.com; # Or localhost location / { root /path/to/your; index index.html; } }Save and close the file.
-
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
Step 3: Starting Nginx
-
Start the Nginx service with the following command:
sudo systemctl start nginx -
Enable Nginx to start at boot:
sudo systemctl enable nginx
Step 4: Adjusting the Firewall
If you have a firewall enabled (like ufw or firewalld), you need to allow HTTP traffic:
-
For
ufw:sudo ufw allow 'Nginx Full' sudo ufw reload -
For
firewalld:sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload
Step 5: Accessing Your Website
Now, open a browser and go to http://yourdomain.com or http://localhost if you didn’t set up a domain. You should see your index.html page served by Nginx.
Troubleshooting
-
If Nginx fails to start or reload, you can check the error messages with:
sudo systemctl status nginxor
sudo journalctl -xeu nginx -
Ensure the
server_nameand the path to yourindex.htmlare correctly specified in your Nginx site configuration.
Congratulations, you have now set up Nginx to serve your HTML page on Arch Linux!