joplin-notes/_resources/nginx.md
2026-11-04 00:33:23 +05:30

3.1 KiB
Raw Permalink Blame History

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

  1. Open your Terminal.

  2. Update your system package database by running:

    sudo pacman -Syu
    
  3. Install Nginx with the following command:

    sudo pacman -S nginx
    

Step 2: Configuring Nginx to Serve Your HTML File

  1. Navigate to the Nginx configuration directory:

    cd /etc/nginx
    
  2. The main configuration file is /etc/nginx/nginx.conf, but for hosting specific sites, it's a good practice to use the sites-available and sites-enabled structure, which might not be set up by default on Arch. Let's create those directories:

    sudo mkdir sites-available
    sudo mkdir sites-enabled
    
  3. Add the following line to the bottom of the nginx.conf file to include the sites-enabled directory. You can open it with your favorite text editor, for example:

    sudo nano nginx.conf
    

    At the bottom of the file, add:

    include /etc/nginx/sites-enabled/*;
    

    Then save and close the file.

  4. Create a new configuration file for your site in the sites-available directory. Replace yourdomain.com with your domain name or localhost if you don’t have one:

    sudo nano sites-available/yourdomain.com
    
  5. Add the following server block (adjust the server_name if using a domain, and change /path/to/your/index.html to the actual path of your index.html file):

    server {
        listen       80;
        server_name  yourdomain.com; # Or localhost
        location / {
            root   /path/to/your;
            index  index.html;
        }
    }
    

    Save and close the file.

  6. 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

  1. Start the Nginx service with the following command:

    sudo systemctl start nginx
    
  2. 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 nginx
    

    or

    sudo journalctl -xeu nginx
    
  • Ensure the server_name and the path to your index.html are correctly specified in your Nginx site configuration.

Congratulations, you have now set up Nginx to serve your HTML page on Arch Linux!