DocsServer ManagementInstalling a Web Server
Server Management 6 min read

Installing a Web Server

Set up Nginx or Apache to serve your websites and applications.

Installing a Web Server

This guide covers installing and configuring Nginx and Apache on your Cd hosting server.

Option 1: Nginx (Recommended)

Nginx is our recommended web server for its performance and low resource usage.

Installation

bash
apt update
apt install nginx -y
systemctl enable nginx
systemctl start nginx

Basic Configuration

Create a new site configuration:

nginx
# /etc/nginx/sites-available/yourdomain.com
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    # Enable gzip compression
    gzip on;
    gzip_types text/plain text/css application/json application/javascript;
}

Enable the site:

bash
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx

SSL with Let's Encrypt

bash
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com

Option 2: Apache

Installation

bash
apt update
apt install apache2 -y
systemctl enable apache2
systemctl start apache2

Virtual Host Configuration

apache
# /etc/apache2/sites-available/yourdomain.com.conf
<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/html
    
    <Directory /var/www/yourdomain.com/html>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Enable the site:

bash
a2ensite yourdomain.com.conf
a2enmod rewrite
systemctl reload apache2
Need help? Chat with us!