How to Deploy a Basic Web Server on Ubuntu Server

How to Deploy a Basic Web Server on Ubuntu Server

Deploying a basic web server on Ubuntu Server is one of the most common first steps for hosting static sites, APIs, single-page applications, or as the foundation for dynamic applications (PHP, Node.js, Python, etc.). In 2026, Nginx remains the most popular and recommended choice for new Ubuntu Server deployments due to its excellent performance, low memory footprint, event-driven architecture, and strong reverse-proxy/load-balancing capabilities.

Apache (httpd) is still widely used and easier for beginners familiar with .htaccess-style configuration, but Nginx generally outperforms it for static content and high-concurrency scenarios.

This guide focuses on Nginx as the primary option (most tutorials and cloud images now favor it), with a shorter Apache alternative at the end.

Prerequisites

  • Fresh or clean Ubuntu Server 24.04 LTS (or 24.04.x point release)
  • Non-root user with sudo privileges
  • Static IP or domain pointed to the server (optional for local testing)
  • Firewall enabled (UFW is default on Ubuntu Server)

Step-by-Step: Install & Configure Basic Nginx Web Server

  1. Update the system Always start here to ensure the latest security patches and package lists.

  2. Install Nginx Nginx is available directly from Ubuntu’s default repositories.

    Bash
    sudo apt update
    sudo apt install nginx -y

    This installs the latest stable Nginx version packaged for Ubuntu (typically 1.24.x or 1.26.x series in 2026).

  3. Start and enable Nginx Nginx should start automatically after installation, but confirm:

    Bash
    sudo systemctl start nginx
    sudo systemctl enable nginx

    Check status:

    Bash
    sudo systemctl status nginx

    Look for “active (running)” in green.

  4. Allow HTTP (and HTTPS) through the firewall Ubuntu Server uses UFW by default.

    Bash
    sudo ufw allow 'Nginx Full'   # allows both 80 and 443
    # or individually:
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw status
  5. Verify the installation From the server itself:

    Bash
    curl http://localhost

    Or open a browser and visit http://your-server-ip You should see the default “Welcome to nginx!” page.

    Default document root: /var/www/html Main config: /etc/nginx/nginx.conf Site configs: /etc/nginx/sites-available/ (symlinked to sites-enabled/)

  6. Deploy your own basic static site Replace or add content to the default root:

    Bash
    echo "<h1>Hello from my Ubuntu Server!</h1><p>Deployed on $(date)</p>" | sudo tee /var/www/html/index.html

    Refresh your browser — the page updates immediately.

  7. Optional: Create a proper virtual host (server block) For production or multiple sites, disable the default site and create your own.

    Bash
    sudo rm /etc/nginx/sites-enabled/default
    sudo nano /etc/nginx/sites-available/my-site

    Minimal example configuration:

    text
    server {
        listen 80;
        listen [::]:80;
    
        server_name your-domain.com www.your-domain.com _;  # _ = catch-all
    
        root /var/www/my-site;
        index index.html index.htm;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }

    Create the document root and test file:

    Bash
    sudo mkdir -p /var/www/my-site
    echo "<h1>My First Nginx Site</h1>" | sudo tee /var/www/my-site/index.html
    sudo chown -R www-data:www-data /var/www/my-site

    Enable the site:

    Bash
    sudo ln -s /etc/nginx/sites-available/my-site /etc/nginx/sites-enabled/
    sudo nginx -t                  # test config syntax
    sudo systemctl reload nginx

Quick Apache Alternative (if you prefer it)

Some users still choose Apache for its mature module ecosystem and .htaccess support.

Bash
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo ufw allow 'Apache Full'

Default page appears at http://your-server-ip. Document root: /var/www/html. Virtual hosts go in /etc/apache2/sites-available/.

Next Steps & Recommendations (2026 Context)

  • Add HTTPS immediately — Use Certbot (Let’s Encrypt):

    Bash
    sudo apt install certbot python3-certbot-nginx -y
    sudo certbot --nginx

    Certbot auto-configures Nginx for TLS 1.3, HSTS, and auto-renewal.

  • Basic security — Install fail2ban, harden SSH, run UFW with deny-by-default incoming.

  • Performance tuning — For Nginx: enable gzip, set worker_processes auto, adjust keepalive_timeout.

  • Monitoring — Add Netdata or Prometheus Node Exporter for real-time visibility.

Nginx remains the go-to for most new Ubuntu Server web deployments in 2026 due to its efficiency and simplicity for static + reverse-proxy use cases.

If you’re planning to host dynamic content (PHP, Python Flask/Django, Node.js), add a reverse proxy setup or containerize with Docker — share your end goal (static site, WordPress, API, etc.) for the next tailored steps!

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!