Complete Guide: Installing Nginx on Your BrainHost VPS

This guide provides comprehensive instructions for installing the Nginx web server on your BrainHost VPS. We will cover the quick installation method using package managers and the detailed compile-from-source method for advanced customization.

Alex Chen

Alex Chen

DevOps Engineer

Oct 25, 2025

10 min read

A step-by-step guide for engineers to install the Nginx web server on a BrainHost VPS, covering both quick installation using package managers (APT/YUM) and advanced compilation from source for custom modules and optimized performance.

I. 🚀 Quick Installation Methods

These methods use your operating system's package manager, offering the fastest and easiest way to deploy Nginx on your BrainHost VPS.

1. Debian/Ubuntu (Using APT)

Bash

# Update the local package index
sudo apt update

# Install Nginx
sudo apt install nginx -y

# Verify the service status
sudo systemctl status nginx

2. RHEL/CentOS/Fedora (Using YUM/DNF)

Bash

# Install the EPEL repository (often necessary for Nginx)
sudo yum install epel-release -y  # or sudo dnf install epel-release -y

# Install Nginx
sudo yum install nginx -y         # or sudo dnf install nginx -y

# Start and enable Nginx to run on boot
sudo systemctl start nginx
sudo systemctl enable nginx

II. ⚙️ Installing Nginx from Source (Compile Installation)

Compiling Nginx from source is the ideal choice when you need to include specific third-party modules, define custom paths, or use the very latest version, ensuring your BrainHost VPS is running a perfectly tailored web server.

Step 1: Install Dependencies

You need development tools and libraries for features like SSL and compression.

OSCommand
Debian/Ubuntusudo apt update && sudo apt install build-essential libpcre3-dev zlib1g-dev libssl-dev -y
RHEL/CentOSsudo yum groupinstall "Development Tools" -y && sudo yum install pcre-devel zlib-devel openssl-devel -y

Step 2: Download and Extract Source Code

Replace 1.27.0 with the latest stable version available.

Bash

cd /usr/local/src
# Download the source code (check the official Nginx site for the latest version)
sudo wget http://nginx.org/download/nginx-1.27.0.tar.gz
# Extract the archive
sudo tar -zxvf nginx-1.27.0.tar.gz
# Change directory into the source folder
cd nginx-1.27.0

Step 3: Configure with Optional Parameters

Use the ./configure script to define installation paths and enable desired modules. This example includes common and useful options for a robust installation on your BrainHost VPS:

ParameterFunction
--prefixDefines the main installation directory.
--user/--groupSets the non-privileged user/group for worker processes.
--with-http_ssl_moduleCrucial: Enables HTTPS/SSL support.
--with-http_v2_moduleEnables HTTP/2 support for faster connections.
--with-http_gzip_static_moduleAllows serving pre-compressed .gz files.
--with-http_stub_status_moduleEnables a simple status page for monitoring.

Bash

sudo ./configure \
    --prefix=/usr/local/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_realip_module \
    --with-http_stub_status_module \
    --with-pcre \
    --with-zlib \
    --with-cc-opt='-O2'

Step 4: Compile and Install

Bash

sudo make
sudo make install

Step 5: Post-Compilation Setup

Since you compiled Nginx, you need to manually set up the user, group, and a system service.

  1. Create the Nginx User and Group:
    Bash
    sudo groupadd nginx
    sudo useradd -r -g nginx -s /bin/false -M nginx
    
  2. Create the systemd Service File:
    This allows you to manage Nginx using systemctl start/stop/status nginx.
    Bash
    # Use your preferred editor (e.g., nano or vi) to create the file
    sudo nano /etc/systemd/system/nginx.service
    

    Paste the following content into the file:
    Ini, TOML
    [Unit]
    Description=The Nginx HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/usr/sbin/nginx -s reload
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
  3. Reload systemd and Start Nginx:
    Bash
    sudo systemctl daemon-reload
    sudo systemctl start nginx
    sudo systemctl enable nginx
    sudo systemctl status nginx
    

III. ✅ Final Verification

After installation, open your web browser and navigate to your BrainHost VPS's IP address or domain name:

  • Example: http://[Your_VPS_IP_Address]

A successful installation will display the Nginx default welcome page.


Would you like me to help you draft the next section of your guide, perhaps focusing on basic Nginx configuration or setting up your first virtual host?

Tags

NginxVPSLinuxWeb ServerDevOpsCompiling
Alex Chen

Alex Chen

DevOps Engineer

DevOps Engineer specializing in cloud infrastructure and automation.

BrainHost - A reliable VPS hosting platform offering high-performance virtual servers with advanced management capabilities.

[email protected]

© 2025 BrainHost. All rights reserved.