Requirements for Installing Nginx 1.14 on Arch Linux

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.

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.

# pacman -S nginx-mainline

Starting Nginx Automatically

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

# 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:

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:

# 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:

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:

Restarting Nginx

Restart the Nginx service to apply the new settings:

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.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: