Tutorials  /  Linux Basics

Install and Configure Nginx on Arch Linux with Virtual Hosts

Ccentron Redaktion · May 2025 ·4 min read ·Linux Basics, Tutorial

Essential Setup

Ensure that you have a server with an updated Arch Linux installation (refer to the appropriate guide). Also, confirm that you possess sudo privileges.

Commands that must be executed as root will be indicated with a # symbol. It is advisable to run these commands using sudo while logged in as a regular user.

Have a text editor installed and know how to use it. Suitable editors include vi, vim, nano, emacs, or another alternative of your choice.

VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Setting Up the Nginx 1.14 Web Server

Preparing Firewall Settings

If you are utilizing a firewall, make sure to allow incoming TCP traffic through port 80.

Installing Nginx

Install Nginx by using the mainline package. This version receives frequent updates. Alternatively, the nginx package provides a more stable, long-term support version. It is advisable to opt for the mainline branch unless specific third-party modules require the stable release.

Console
# pacman -S nginx-mainline

Starting Nginx Automatically

Enable and initiate Nginx immediately, and configure it to start with every system boot:

Console
# systemctl enable --now nginx

Verifying Nginx Operation

To confirm that Nginx is running, navigate to http://YOUR-SERVER-WEB-ADDRESS-OR-IP in your browser. If necessary, you can determine your server’s IP address by executing:

Console
# ip addr

Understanding Nginx Configuration

The configuration files for Nginx reside in the /etc/nginx directory. The primary configuration file is nginx.conf.

Within the configuration, the directive server.location.root /usr/share/nginx/html; determines the default directory for serving web content.

Typically, Nginx’s main process operates with root privileges, while its worker processes run under the user http.

Access logs for Nginx are stored at /var/log/nginx/access.log.

Configuring Virtual Hosts with Nginx

Overview of Virtual Hosting

It is possible to serve multiple domain names from a single Nginx server instance, each displaying distinct content.

Setting Up Virtual Host Directories

Create a directory to store your virtual host configuration files:

Console
# mkdir /etc/nginx/sites-enabled

Creating Virtual Host Configuration Files

Generate a separate configuration file for each domain. For instance, create /etc/nginx/sites-enabled/YOUR-DOMAIN-NAME.com and insert the following content:

Code
server {
    listen 80;
    server_name YOUR-DOMAIN-NAME.com;

    location / {
        root /usr/share/nginx/YOUR-DOMAIN-NAME.com;
        index index.html index.htm;
    }
}

Updating the Main Configuration File

At the conclusion of the http block in /etc/nginx/nginx.conf, insert the following directive to load the virtual host configurations:

Code
include sites-enabled/*;

Restarting Nginx

Restart the Nginx service to apply the new settings:

Console
# systemctl restart nginx

Behavior of Domain Requests

When a request is made to YOUR-DOMAIN-NAME.com, Nginx will serve files from /usr/share/nginx/YOUR-DOMAIN-NAME.com.

Requests that do not match a defined server_name (such as requests directly to the server’s IP address or other domains pointing to it) will default to serving content from the general server block. This default location is configured via location.root in /etc/nginx/nginx.conf, typically pointing to /usr/share/nginx/html/.

Conclusion

By following this guide, you can successfully install and configure Nginx on an Arch Linux server, including setting up multiple virtual hosts for different domains. With these configurations, your server will be able to efficiently manage and serve web content for various sites from a single system.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren