Set up Nginx or Apache to serve your websites and applications.
This guide covers installing and configuring Nginx and Apache on your Cd hosting server.
Nginx is our recommended web server for its performance and low resource usage.
apt update
apt install nginx -y
systemctl enable nginx
systemctl start nginx
apt update
apt install nginx -y
systemctl enable nginx
systemctl start nginx
Create a new site configuration:
# /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;
}
# /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:
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com
apt update
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
apt update
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
# /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>
# /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:
a2ensite yourdomain.com.conf
a2enmod rewrite
systemctl reload apache2
a2ensite yourdomain.com.conf
a2enmod rewrite
systemctl reload apache2