How to Connect to Your VDS Server via SSH (Complete Guide)
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Install and configure Nginx and Apache web servers, compare their strengths, set up virtual hosts, configure SSL/TLS, and manage web services on Linux.
Nginx and Apache are the two most widely used web servers in the world. Both can serve web applications, static files, and act as reverse proxies on Linux servers. This guide covers installation, basic configuration, and virtual host setup for both.
| Feature | Nginx | Apache |
|---|---|---|
| Architecture | Async, event-driven | Process/thread-based |
| Static files | Very fast | Slower |
| Dynamic content | Requires reverse proxy | Built-in modules |
| Memory usage | Low | Higher |
| Configuration | Simpler | .htaccess support |
| Best for | High-traffic sites | PHP applications |
Choose Nginx for high-traffic static content or reverse proxy; choose Apache for PHP-based applications (WordPress, Laravel). They can also be used together: Nginx as a front-end reverse proxy, Apache as the back-end application server.
# Update package list
sudo apt update
# Install Nginx
sudo apt install nginx -y
# Start and enable the service
sudo systemctl start nginx
sudo systemctl enable nginx
# Check status
sudo systemctl status nginx
# Add EPEL repository
sudo dnf install epel-release -y
# Install Nginx
sudo dnf install nginx -y
# Start and enable the service
sudo systemctl start nginx
sudo systemctl enable nginx
# Test configuration
sudo nginx -t
# Reload configuration (no downtime)
sudo systemctl reload nginx
# Restart service
sudo systemctl restart nginx
# Show Nginx version
nginx -v
In Nginx, create a separate configuration file under /etc/nginx/sites-available/ for each site.
# Create configuration file
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
# For PHP-FPM
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
# Block access to hidden files
location ~ /\.ht {
deny all;
}
# Log files
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
}
# Enable the site
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
# Create web directory
sudo mkdir -p /var/www/example.com/html
sudo chown -R www-data:www-data /var/www/example.com
# Test and reload
sudo nginx -t && sudo systemctl reload nginx
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
# Install Apache
sudo apt update
sudo apt install apache2 -y
# Start and enable the service
sudo systemctl start apache2
sudo systemctl enable apache2
# Check status
sudo systemctl status apache2
# Install Apache (httpd)
sudo dnf install httpd -y
# Start and enable the service
sudo systemctl start httpd
sudo systemctl enable httpd
# Test configuration
sudo apachectl configtest
# Reload configuration
sudo systemctl reload apache2
# Enable modules
sudo a2enmod rewrite
sudo a2enmod ssl
# Enable/disable sites
sudo a2ensite example.com
sudo a2dissite 000-default
# Create configuration file
sudo nano /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
<Directory /var/www/example.com/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
# Create web directory
sudo mkdir -p /var/www/example.com/html
sudo chown -R www-data:www-data /var/www/example.com
# Enable the site
sudo a2ensite example.com.conf
# Test and reload
sudo apachectl configtest && sudo systemctl reload apache2
Use Certbot for a free SSL certificate:
# Install Certbot
sudo apt install certbot -y
# For Nginx
sudo apt install python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
# For Apache
sudo apt install python3-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com
# Test automatic renewal
sudo certbot renew --dry-run
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/example.com/html;
index index.html;
}
# Redirect HTTP to HTTPS
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
# Allow HTTP and HTTPS with ufw
sudo ufw allow 'Nginx Full'
# or
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# For Apache
sudo ufw allow 'Apache Full'
On REXE servers, also remember to open HTTP (80) and HTTPS (443) ports from the Path Panel firewall.
Nginx and Apache are powerful web servers for different use cases. Nginx is ideal for high-performance static content and reverse proxy, while Apache is preferred for PHP applications and .htaccess-based configurations. With virtual host configuration on either server, multiple domains can be hosted on the same server.
Nginx offers better performance for high-traffic sites, static content, or reverse proxy. Apache is easier to configure for PHP applications like WordPress and Laravel (with .htaccess support). Using both together is also possible: Nginx in front, Apache in the back.
This is done with virtual host configuration. In Nginx, create a separate file under /etc/nginx/sites-available/ for each domain and add a symlink to sites-enabled. In Apache, create a .conf file under /etc/apache2/sites-available/ and enable it with a2ensite.
You can get a free SSL certificate with Let's Encrypt. Install Certbot: 'sudo apt install certbot python3-certbot-nginx -y'. Then run 'sudo certbot --nginx -d example.com' to automatically install and configure the certificate. Certificates auto-renew every 90 days.
The 'sudo nginx -t' command tests configuration files and shows errors. Read the error message carefully; it usually specifies the file name and line number. You can also check service logs with 'sudo journalctl -u nginx'.
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Complete guide to connecting to Windows Server VDS via Remote Desktop (RDP): setup steps, NLA security, Path Panel firewall rule, and troubleshooting tips.
Step-by-step guide to changing your VDS server OS via REXE panel: backup tips, supported Linux distributions and Windows Server versions explained.