bolt Valebyte VPS from $4/mo — NVMe, 60s deploy.

Get a VPS arrow_forward
eco Beginner Tutorial/How-to

Host Multiple Websites on Your Dedicated Server with Nginx

calendar_month Jun 28, 2026 schedule 9 min read visibility 12 views
Host Multiple Websites on Your Dedicated Server with Nginx
info

Need a server for this guide? We offer dedicated servers and VPS in 50+ countries with instant setup.

Leveraging the raw power of a dedicated server allows for unparalleled control, performance, and scalability. One of the most common and efficient ways to maximize this potential is by hosting multiple websites on a single machine. This tutorial will walk you through setting up Nginx to serve several domains from your Valebyte dedicated server, ensuring each site runs optimally.

Need a server for this guide?

Deploy a VPS or dedicated server in minutes.

Why Host Multiple Websites on a Dedicated Server?

Dedicated servers provide exclusive access to all their resources—CPU, RAM, storage, and network bandwidth. This contrasts sharply with shared hosting, where resources are split among many users, or even VPS, which, while offering more isolation, still virtualizes hardware. For businesses, developers, and sysadmins, a dedicated server from Valebyte offers:

  • Unmatched Performance: No noisy neighbors competing for resources means consistent, high-speed performance for all your sites. Ideal for high-traffic web applications, e-commerce stores, and data-intensive services.
  • Enhanced Security: Full control over your server environment allows for custom security configurations, firewalls, and monitoring tailored to your specific needs, reducing vulnerability risks.
  • Total Control & Flexibility: Install any software, configure any settings, and optimize your environment exactly how you want it. This is crucial for complex setups like custom web applications, CI/CD pipelines, or specialized game servers that might also require web interfaces.
  • Cost Efficiency: For a growing portfolio of websites or applications, consolidating them onto a single powerful dedicated server can be more cost-effective than managing multiple smaller hosting plans.
  • Scalability: Easily upgrade hardware components or add more dedicated servers as your needs expand, ensuring your infrastructure can grow with your business.

Whether you're running a suite of business websites, managing client projects, hosting a popular game server with a web frontend, or developing multiple applications, a dedicated server with Nginx is an excellent choice for efficient resource utilization.

Prerequisites and Server Requirements

Before we begin configuring Nginx, ensure you have the following:

  • A Valebyte Dedicated Server: With root or sudo access.
  • Operating System: A Linux distribution (e.g., Ubuntu 22.04 LTS, Debian 11, CentOS 8 Stream). This tutorial will use Ubuntu 22.04 LTS examples, but commands are largely similar for other Debian-based systems.
  • Nginx Installed: If Nginx isn't already installed, we'll cover its installation.
  • Registered Domain Names: You'll need at least two domain names (e.g., example1.com and example2.com) that you wish to host.
  • DNS Configuration: The A records for your domain names (e.g., example1.com, www.example1.com, example2.com, www.example2.com) must point to your dedicated server's public IP address. DNS changes can take a few hours to propagate globally.
  • Basic Command-Line Familiarity: Comfort with SSH and basic Linux commands.

Step-by-Step Guide: Setting Up Multiple Websites with Nginx

Step 1: Connect to Your Server and Update System

First, connect to your Valebyte dedicated server via SSH:

ssh username@your_server_ip

Once logged in, update your system's package list and upgrade any existing packages to ensure you have the latest security patches and software:

sudo apt update
sudo apt upgrade -y

Step 2: Install Nginx (if not already installed)

If Nginx is not already on your server, install it:

sudo apt install nginx -y

After installation, Nginx should start automatically. You can verify its status:

sudo systemctl status nginx

You should see output indicating Nginx is active (running). If not, start and enable it:

sudo systemctl start nginx
sudo systemctl enable nginx

Ensure your firewall (e.g., UFW) allows HTTP (port 80) and HTTPS (port 443) traffic:

sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo ufw enable

Step 3: Create Document Root Directories for Each Website

Nginx serves files from specific directories, known as document roots. It's good practice to create a separate directory for each website. We'll use /var/www/ as the base directory.

Let's create directories for two example websites: example1.com and example2.com. Replace these with your actual domain names.

sudo mkdir -p /var/www/example1.com/html
sudo mkdir -p /var/www/example2.com/html

Assign ownership of these directories to the www-data user and group, which Nginx uses to serve files. This ensures Nginx has the necessary permissions.

sudo chown -R www-data:www-data /var/www/example1.com
sudo chown -R www-data:www-data /var/www/example2.com

Set appropriate directory permissions:

sudo chmod -R 755 /var/www/example1.com
sudo chmod -R 755 /var/www/example2.com

Step 4: Create Sample Index Files for Testing

To easily verify that each website is being served correctly, create a simple index.html file within each document root.

For example1.com:

echo "<!DOCTYPE html><html><head><title>Welcome to Example 1</title></head><body><h1>Hello from Example 1!</h1><p>This is the first website on your Valebyte dedicated server.</p></body></html>" | sudo tee /var/www/example1.com/html/index.html

For example2.com:

echo "<!DOCTYPE html><html><head><title>Welcome to Example 2</title></head><body><h1>Greetings from Example 2!</h1><p>This is the second website on your Valebyte dedicated server.</p></body></html>" | sudo tee /var/www/example2.com/html/index.html

Step 5: Configure Nginx Server Blocks (Virtual Hosts)

Nginx uses 'server blocks' (similar to Apache's virtual hosts) to define configurations for individual websites. These files are typically stored in /etc/nginx/sites-available/ and then symbolically linked to /etc/nginx/sites-enabled/ to activate them.

Create Configuration for example1.com

Open a new file for example1.com using a text editor like Nano:

sudo nano /etc/nginx/sites-available/example1.com.conf

Paste the following configuration, replacing example1.com with your domain name:

server {
    listen 80;
    listen [::]:80;

    root /var/www/example1.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name example1.com www.example1.com;

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

    error_log /var/log/nginx/example1.com_error.log;
    access_log /var/log/nginx/example1.com_access.log;
}

Explanation of directives:

  • listen 80; and listen [::]:80;: Nginx listens for incoming connections on port 80 for both IPv4 and IPv6.
  • root /var/www/example1.com/html;: Specifies the document root directory for this website.
  • index index.html ...;: Defines the order in which Nginx looks for index files.
  • server_name example1.com www.example1.com;: Tells Nginx which domain names this server block should respond to. Crucial for hosting multiple sites.
  • location / { ... }: Defines how Nginx handles requests for files not found directly. try_files attempts to serve the requested URI, then the URI as a directory, and finally returns a 404 error.
  • error_log and access_log: Custom log files for each site, making troubleshooting and monitoring easier.

Save and close the file (Ctrl+X, Y, Enter in Nano).

Create Configuration for example2.com

Repeat the process for your second domain:

sudo nano /etc/nginx/sites-available/example2.com.conf

Paste the configuration, adjusting for example2.com:

server {
    listen 80;
    listen [::]:80;

    root /var/www/example2.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name example2.com www.example2.com;

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

    error_log /var/log/nginx/example2.com_error.log;
    access_log /var/log/nginx/example2.com_access.log;
}

Save and close the file.

Step 6: Enable Server Blocks and Restart Nginx

To activate your new server blocks, create symbolic links from sites-available to sites-enabled:

sudo ln -s /etc/nginx/sites-available/example1.com.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/example2.com.conf /etc/nginx/sites-enabled/

It's often a good idea to remove the default Nginx server block to avoid conflicts or serving unintended content:

sudo rm /etc/nginx/sites-enabled/default

Before restarting Nginx, always test your configuration for syntax errors:

sudo nginx -t

You should see output similar to:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If there are no errors, restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 7: Configure DNS Records

This step is crucial and must be done through your domain registrar or DNS management service. For each domain (example1.com and example2.com), you need to create or modify the following A records:

  • An A record for the root domain (e.g., example1.com) pointing to your dedicated server's IP address.
  • An A record for the www subdomain (e.g., www.example1.com) also pointing to your dedicated server's IP address.

DNS changes can take anywhere from a few minutes to 48 hours to fully propagate across the internet. You can use online tools like DNS Checker to monitor propagation.

Step 8: Test Your Websites

Once DNS propagation has completed, open your web browser and navigate to http://example1.com and http://example2.com. You should see the respective 'Hello from Example 1!' and 'Greetings from Example 2!' messages.

You can also test from your server's command line using curl, explicitly setting the Host header to simulate a browser request:

curl -H "Host: example1.com" http://localhost
curl -H "Host: example2.com" http://localhost

Or, once DNS has propagated:

curl http://example1.com
curl http://example2.com
rocket_launch Quick pick

Need a dedicated server?

Compare prices from top providers. Configure and order in minutes.

Browse dedicated servers arrow_forward

Advanced Considerations for Dedicated Server Hosting

SSL/TLS with Let's Encrypt

For secure communication, all modern websites should use HTTPS. Let's Encrypt provides free SSL/TLS certificates, and Certbot automates the process. Install Certbot for Nginx:

sudo apt install certbot python3-certbot-nginx -y

Then, request and configure certificates for your domains:

sudo certbot --nginx -d example1.com -d www.example1.com -d example2.com -d www.example2.com

Certbot will guide you through the process, modify your Nginx configurations, and set up automatic renewal.

Integrating with PHP-FPM

If your websites run PHP applications (like WordPress, Laravel, etc.), you'll need PHP-FPM (FastCGI Process Manager). Install it along with common PHP extensions:

sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y

Then, modify your Nginx server block to pass PHP requests to PHP-FPM. Add a location ~ \.php$ block:

server {
    # ... other directives ...

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Adjust PHP version if different
    }

    # ... other directives ...
}

Remember to restart Nginx and PHP-FPM after changes:

sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx

Security Best Practices

  • Firewall (UFW): Keep only necessary ports open (22 for SSH, 80 for HTTP, 443 for HTTPS).
  • Regular Updates: Keep your OS and Nginx updated.
  • Strong Passwords/SSH Keys: Use strong, unique passwords and SSH keys for server access.
  • Rate Limiting: Use Nginx's limit_req module to protect against DDoS attacks for high-traffic sites.
  • Fail2Ban: Install Fail2Ban to automatically ban IPs with too many failed login attempts.

Monitoring and Logging

Dedicated servers provide full access to logs. Regularly check Nginx access and error logs (e.g., /var/log/nginx/example1.com_access.log and /var/log/nginx/example1.com_error.log) for insights into traffic and issues. Consider tools like Logrotate for managing log file sizes and Prometheus/Grafana for advanced monitoring.

Troubleshooting Common Issues

Even with careful setup, issues can arise. Here are common problems and their solutions:

1. Nginx Configuration Syntax Errors

Symptom: Nginx fails to restart, or nginx -t reports errors. Solution: The nginx -t command is your best friend. It will pinpoint the exact file and line number of the syntax error. Carefully review the reported line for typos, missing semicolons, incorrect directives, or unclosed brackets.

2. Websites Not Loading or Showing Default Nginx Page

Symptom: Browser shows a 404 error, a generic Nginx welcome page, or a different website than expected. Solutions:

  • DNS Propagation: Verify your domain's A records correctly point to your dedicated server's IP. Use dig example1.com or online DNS checkers.
  • Server Name Mismatch: Double-check the server_name directive in your Nginx configuration. It must exactly match the domain names being requested.
  • Symbolic Links: Ensure the symbolic links in /etc/nginx/sites-enabled/ are correctly pointing to your configuration files in /etc/nginx/sites-available/.
  • Default Server Block: If you see the default Nginx page, you might not have removed or correctly configured the default server block (/etc/nginx/sites-enabled/default).
  • Nginx Restart: Always restart Nginx after making configuration changes (sudo systemctl restart nginx).

3. Permissions Issues (403 Forbidden)

Symptom: Browser shows a '403 Forbidden' error. Solution: This usually means Nginx doesn't have permission to read the files or directories. Ensure the document root and its contents are owned by www-data:www-data and have appropriate read permissions (e.g., sudo chown -R www-data:www-data /var/www/example1.com and sudo chmod -R 755 /var/www/example1.com).

4. Port Conflicts

Symptom: Nginx fails to start, or logs indicate 'address already in use'. Solution: Another service might be listening on port 80 or 443. Check for other web servers (like Apache) or services. Use sudo netstat -tulpn | grep :80 to identify the conflicting process and either stop it or change its port.

5. Nginx Logs

Symptom: Unclear what the problem is. Solution: Always check your Nginx error logs. For global errors, look at /var/log/nginx/error.log. For specific website issues, check the custom error logs you defined (e.g., /var/log/nginx/example1.com_error.log). These logs provide invaluable clues about what's going wrong.

sudo tail -f /var/log/nginx/example1.com_error.log

This command will display the last few lines of the log and continue to show new entries as they appear, which is helpful for real-time debugging.

By systematically checking these points, you can resolve most common issues when setting up multiple websites on your dedicated server with Nginx.

check_circle Conclusion

Harnessing the full power of your Valebyte dedicated server to host multiple websites with Nginx is a smart, scalable, and secure approach for any growing online presence. From simple static sites to complex web applications, game servers, or streaming platforms, Nginx's efficiency combined with dedicated resources ensures optimal performance. Follow this guide to confidently deploy and manage your diverse web portfolio. Ready to take control of your web hosting? Explore Valebyte's robust dedicated server solutions today and elevate your online infrastructure.

help Frequently Asked Questions

Was this guide helpful?

dedicated server multiple websites Nginx host multiple domains Nginx Nginx virtual hosts dedicated server bare-metal hosting multiple sites Valebyte dedicated server Nginx configure Nginx server blocks setup multiple websites Linux dedicated server web hosting Nginx for sysadmins website performance dedicated server
support_agent
Valebyte Support
Usually replies within minutes
Hi there!
Send us a message and we'll reply as soon as possible.