Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Self-hosting

Host several websites on one VPS with Nginx, Apache or IIS

Run several websites on one VPS: name-based virtual hosts in Nginx, Apache and IIS, one user and PHP pool per site, a catch-all for unknown names, and TLS.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of one server tower holding several glowing website windows stacked like floors
On this pageHow one address serves many names

One server with one IP address can serve many websites. The web server reads the name the visitor asked for and picks the matching site. Getting that part working takes ten minutes. Doing it well means each site gets its own directory, system user, PHP pool, database user, logs and certificate, so a hacked plugin on one site cannot read the others, and a default host refuses names you never configured. This guide builds that layout on Ubuntu 24.04 with PHP 8.3 (adjust the version in paths on other releases), then shows the same idea in IIS.

How one address serves many names

Over HTTP, the browser sends the site name in the Host header. Over HTTPS, it sends it earlier, in the Server Name Indication (SNI) field of the TLS handshake, so the server can choose the right certificate before any HTTP is exchanged. Every current browser and HTTP client sends SNI, so HTTPS sites no longer need one IP address each.

Separate these per site:

Per site Why it matters
Directory under /srv/www/ Clear permissions and one folder to back up
System user A compromised site cannot read other sites' files
PHP-FPM pool Its own user, process limit and slow log
Database and database user One leaked password exposes one database
Log files Trouble is traced to one site at a glance
Certificate Renewed and revoked independently

Prepare the site on Ubuntu

Create a user without a login shell, and a directory it owns. The web server's group gets read access, and the setgid bit makes new files inherit that group:

sudo useradd --system --user-group --home-dir /srv/www/shop --shell /usr/sbin/nologin shop
sudo mkdir -p /srv/www/shop/public
sudo chown -R shop:www-data /srv/www/shop
sudo chmod 2750 /srv/www/shop /srv/www/shop/public

Other site users are not in www-data, so mode 2750 keeps them out of the directory entirely. Then give the site its own PHP-FPM pool in /etc/php/8.3/fpm/pool.d/shop.conf:

[shop]
user = shop
group = shop
listen = /run/php/php8.3-fpm-shop.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = ondemand
pm.max_children = 8
pm.process_idle_timeout = 30s

request_slowlog_timeout = 5s
slowlog = /var/log/php8.3-fpm-shop-slow.log

Reload with sudo systemctl reload php8.3-fpm. With pm = ondemand, an idle site holds no PHP processes, which matters when most of your sites are quiet. Finally create a database and a user that can reach only that database.

Nginx: one server block per site

Put each site in its own file under /etc/nginx/sites-available/:

server {
    listen 80;
    listen [::]:80;
    server_name shop.example.com www.shop.example.com;
    root /srv/www/shop/public;
    index index.php index.html;

    access_log /var/log/nginx/shop.access.log;
    error_log  /var/log/nginx/shop.error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm-shop.sock;
    }
}

Enable it, test, reload, then let certbot add HTTPS to that block:

sudo ln -s /etc/nginx/sites-available/shop.example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d shop.example.com -d www.shop.example.com

Refuse names you do not serve

When no server_name matches, nginx hands the request to the default server for that port. Unless you choose one, that is simply the first block it loaded, so a request for your bare IP address, or for a stranger's domain pointed at your server, shows one of your sites. Replace Ubuntu's default site with a catch-all:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;
    ssl_reject_handshake on;
    return 444;
}
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx

return 444 closes the connection without an answer, and ssl_reject_handshake on refuses TLS for unknown names, so the catch-all needs no certificate of its own.

Apache: one virtual host per site

Apache routes PHP to each pool with a handler inside the virtual host, instead of the global php8.3-fpm configuration that sends every site to the same pool. Enable the proxy modules once with sudo a2enmod proxy_fcgi setenvif, then write /etc/apache2/sites-available/shop.example.com.conf:

<VirtualHost *:80>
    ServerName shop.example.com
    ServerAlias www.shop.example.com
    DocumentRoot /srv/www/shop/public

    <Directory /srv/www/shop/public>
        AllowOverride None
        Require all granted
    </Directory>

    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php/php8.3-fpm-shop.sock|fcgi://shop"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/shop.error.log
    CustomLog ${APACHE_LOG_DIR}/shop.access.log combined
</VirtualHost>

Give each site a different name after fcgi://, so Apache never treats two pools as one backend. Turn on AllowOverride only for sites whose software relies on .htaccess. Enable the site with sudo a2ensite shop.example.com, then run sudo apache2ctl configtest and sudo systemctl reload apache2.

Apache also falls back to the first virtual host it loads, which on Ubuntu is 000-default.conf and its placeholder page. Disable it and load a catch-all first:

# /etc/apache2/sites-available/000-catch-all.conf
<VirtualHost *:80>
    ServerName catch-all.invalid
    <Location "/">
        Require all denied
    </Location>
</VirtualHost>

Run sudo a2dissite 000-default and sudo a2ensite 000-catch-all, then reload. Unlike nginx, Apache cannot refuse the TLS handshake, so a default HTTPS host still needs a certificate, even a self-signed one. Certbot's Apache plugin (certbot --apache -d shop.example.com) handles each real site.

IIS on Windows Server

IIS uses the same model: each site has a binding made of address, port and host name, and HTTPS bindings use SNI. In PowerShell run as administrator:

Import-Module WebAdministration
New-Item -ItemType Directory -Path "C:\sites\shop" -Force
New-WebAppPool -Name "shop"
New-Website -Name "shop" -PhysicalPath "C:\sites\shop" -ApplicationPool "shop" -Port 80 -HostHeader "shop.example.com"
New-WebBinding -Name "shop" -Protocol "https" -Port 443 -HostHeader "shop.example.com" -SslFlags 1
$thumb = (Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -eq "CN=shop.example.com" }).Thumbprint
(Get-WebBinding -Name "shop" -Protocol "https" -Port 443).AddSslCertificate($thumb, "my")

-SslFlags 1 marks the binding as SNI. Each application pool runs as its own identity, here IIS AppPool\shop. To keep sites apart, serve anonymous requests under that identity instead of the shared IUSR account, remove the inherited read access for Users from C:\sites, and grant each pool its own folder only:

Set-WebConfigurationProperty -PSPath "MACHINE/WEBROOT/APPHOST" -Filter "system.webServer/security/authentication/anonymousAuthentication" -Name "userName" -Value ""
icacls "C:\sites" /inheritance:r /grant:r "Administrators:(OI)(CI)F" "SYSTEM:(OI)(CI)F"
icacls "C:\sites\shop" /grant "IIS AppPool\shop:(OI)(CI)RX"

The Default Web Site answers every name without a binding; stop it, or point it at an empty folder. An ACME client for Windows such as win-acme can request Let's Encrypt certificates and keep the HTTPS bindings updated.

When a separate IP address still helps

SNI made one IP per site unnecessary, but a dedicated address still earns its place when one site needs its own firewall rules, its own reverse DNS, or a quick move to another server. A CloudSat floating IP costs $2.00 a month and moves between servers in the same region from the console, so a busy site can change servers without waiting for DNS; you add the address inside the operating system yourself.

Keep one site from starving the others

  • Cap PHP per pool. pm.max_children limits how many processes, and so how much memory, a site can take. Size it from the memory one process really uses.
  • Limit abusive traffic per site with limit_req and limit_conn in that site's server block.
  • Cap database connections per user, for example ALTER USER 'shop'@'localhost' WITH MAX_USER_CONNECTIONS 20; in MariaDB or MySQL.
  • Watch the slow logs. The pool's slow log shows which script holds workers, before the site takes the server down with it.

When one site keeps outgrowing its limits, give it its own server rather than raising every cap.

Backups and logs per site

Back up each site as a unit: its directory plus a dump of its database, for example mysqldump --single-transaction shop_db, copied off the server. Restoring one site then touches nothing else. Per-site logs under /var/log/nginx/ or /var/log/apache2/ are rotated by the package's logrotate rules, which match every .log file there. The PHP-FPM slow logs are not, so give them a logrotate rule of their own.

On CloudSat, the LEMP app installs Nginx, PHP-FPM and a MySQL-compatible database ready for this layout, and a Windows VPS covers the IIS route.

FAQ

How many websites can one VPS host?

There is no fixed number. Static sites cost almost nothing, and quiet PHP sites with ondemand pools use memory only while they work. The limit is the busiest sites' traffic and the memory their workers need, so watch memory and response times as you add sites.

Do I need a separate IP address for each HTTPS site?

No. SNI lets one address carry certificates for any number of names. Separate addresses are for separate firewall rules, reverse DNS, or moving one site independently.

Should each site run in its own container instead?

Containers give stronger isolation and let sites use different runtime versions, at the cost of a reverse proxy in front and more moving parts. Our comparison of Caddy and Nginx as a reverse proxy covers that layout.

Can two sites use different PHP versions?

Yes, with one pool per version, each with its own socket. Ubuntu's archive ships one PHP version per release, so a second version means a third-party repository or a container.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.