Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Host Multiple Websites with Nginx and PHP-FPM on a VPS

A practical, security-conscious guide to serving several domains from one VPS with NGINX server blocks, PHP-FPM, separate roots, DNS and HTTPS SNI.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Host multiple domains on one VPS by giving each site its own NGINX server block, document root, logs and (when appropriate) PHP-FPM pool. NGINX chooses a block from the request’s Host header, while TLS SNI lets each HTTPS domain use the right certificate on the same IP. Build the sites in HTTP first, verify DNS and PHP, then add certificates and redirects.

How one VPS serves several domains

NGINX can define multiple virtual servers by placing multiple server directives inside the http context. Each block describes a domain’s names, files, routing and PHP hand-off. The browser sends a hostname in the HTTP Host header; NGINX uses that value to select the matching block. The official web-server guide documents this model at https://docs.nginx.com/nginx/admin-guide/web-server/web-server/.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How NGINX picks a server block

Matching is deterministic. NGINX checks an exact server_name first, then the longest matching wildcard, then the first matching regular expression; the search stops at the first applicable variant. See https://nginx.org/en/docs/http/server_names.html. If no name matches, NGINX sends the request to the default server for that listening port, as described at https://nginx.org/en/docs/http/request_processing.html?from=20423&from_column=20423. Make the default deliberate so an unknown hostname cannot accidentally expose another site.

How PHP is executed

NGINX does not run PHP itself. A PHP location forwards the request with fastcgi_pass to PHP-FPM over a Unix-domain socket or TCP address. fastcgi_param SCRIPT_FILENAME identifies the script PHP-FPM must execute. The directive behavior and parameter handling are documented in the FastCGI reference at https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

How HTTPS works on one IP

During the TLS handshake, SNI carries the requested hostname. The server can therefore select the certificate and HTTPS configuration for each domain sharing the address. NGINX describes SNI as the general solution for several HTTPS servers on one IP at https://nginx.org/en/docs/http/configuring_https_servers.html?authuser=0.

Plan the VPS before writing configuration

Capacity is workload-specific. There are no universal site-count or visitor thresholds: measure CPU, memory, storage, PHP execution time and database load on the actual applications. Decide the following before creating blocks.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision Practical choice Why it matters
Operating system Use a currently supported distribution and its maintained NGINX, PHP and PHP-FPM packages. Package names, service names, socket paths and FastCGI include files vary by distribution and PHP version.
Site layout One document root per domain, such as /var/www/site-a/public and /var/www/site-b/public. Separate roots prevent one site’s files from being selected by another block.
Writable data Give each application write access only to its upload, cache or other required directories. Limiting write scope reduces the impact of a compromised application.
PHP model Use a shared PHP-FPM pool for simplicity, or separate pools when isolation is worth additional memory and administration. Pool choice affects failure blast radius, credentials and resource controls.
Addressing Point every domain’s A and, if used, AAAA record to the VPS address. HTTP and certificate validation must reach this machine for each hostname.
Operations Plan per-site logs, backups, updates, firewall rules and log rotation. Multiple sites multiply maintenance tasks even when they share one server.

Install the supported packages

Install NGINX, PHP and the PHP-FPM service from the target distribution’s supported repositories. On a Debian-family system, the package names are commonly nginx, php-fpm and any application-specific PHP extensions; on an RPM-family system, use that distribution’s equivalent package names. Confirm the installed PHP-FPM service and socket instead of assuming a versioned path. Start and enable the services using the distribution’s service manager.

Create an isolated filesystem layout

Create a root for every site and keep application code separate from data that must be writable. A simple layout is:

/var/www/site-a/public       # web-visible files for site-a.example
/var/www/site-a/storage      # uploads/cache if the application needs it
/var/www/site-b/public       # web-visible files for site-b.example
/var/www/site-b/storage

Ownership and permissions

Choose an ownership model deliberately. A deploy user can own the code while the PHP-FPM worker group receives write permission only on named storage directories. Do not make an entire document root world-writable. Ensure the NGINX worker can traverse parent directories and read public files, but cannot modify application code unless the application explicitly requires it.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Keep secrets out of the public root

Place environment files, database credentials and deployment keys outside public. If an application requires a configuration file beneath the root, add an explicit deny rule or follow that application’s documented safe layout. The safest arrangement is one in which a request can never map directly to a secret file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build one HTTP server block per domain

Start without HTTPS so DNS, host matching and PHP can be tested independently. The following pattern is intentionally illustrative: replace domain names, roots, include filenames and the PHP-FPM socket with values present on your VPS.

server {
    listen 80;
    server_name site-a.example www.site-a.example;

    root /var/www/site-a/public;
    index index.php index.html;

    access_log /var/log/nginx/site-a.access.log;
    error_log  /var/log/nginx/site-a.error.log;

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

    location ~ .php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }

    location ~* .(css|js|jpg|jpeg|png|gif|svg|ico|webp)$ {
        try_files $uri =404;
    }
}

server {
    listen 80;
    server_name site-b.example www.site-b.example;

    root /var/www/site-b/public;
    index index.php index.html;

    access_log /var/log/nginx/site-b.access.log;
    error_log  /var/log/nginx/site-b.error.log;

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

    location ~ .php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }

    location ~* .(css|js|jpg|jpeg|png|gif|svg|ico|webp)$ {
        try_files $uri =404;
    }
}

The front-controller fallback in location / is suitable only for applications that document that routing pattern. A simple static site can instead use try_files $uri $uri/ =404;. Do not send every arbitrary path to PHP: the explicit PHP location and a controlled static-file result prevent NGINX from treating unexpected filenames as scripts.

Use the correct FastCGI include

Use the maintained FastCGI parameter file supplied by your distribution, often named fastcgi_params or fastcgi.conf. POST requests need parameters including REQUEST_METHOD, CONTENT_TYPE and CONTENT_LENGTH; the distribution include normally supplies the standard set. If your package provides an application-specific include, follow its documented convention rather than copying a file from another operating system.

Find and verify the PHP-FPM socket

The socket in the example is not universal. List the runtime directory used by your distribution and inspect the PHP-FPM pool configuration to find the active listen value. It may be a versioned Unix socket such as /run/php/php8.x-fpm.sock, or a TCP address such as 127.0.0.1:9000. Set fastcgi_pass to exactly that value and make sure the NGINX worker has permission to connect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Enable and validate the configuration

  1. Save each block in the directory your distribution loads from, commonly /etc/nginx/sites-available/ with a symlink into /etc/nginx/sites-enabled/, or a file under /etc/nginx/conf.d/.
  2. Check syntax and referenced files with sudo nginx -t. Fix every error before touching the running service.
  3. Reload, rather than stop, NGINX after a successful test: sudo systemctl reload nginx (use the service command provided by your distribution).
  4. Repeat nginx -t before every later reload. A failed test should leave the known-good configuration running.

Test host routing before DNS and certificates

When DNS has not propagated, send the intended Host header directly to the VPS address:

curl -i -H 'Host: site-a.example' http://203.0.113.10/
curl -i -H 'Host: site-b.example' http://203.0.113.10/

Replace the address with the VPS’s real IPv4 address. The two responses should come from different roots. Test each apex and www name that appears in server_name. A request with an unknown host should land in your intentional default server, not in a customer site.

Verify DNS records

Create the required A records and, only when the VPS is configured for IPv6, AAAA records. Query the records with your operating system’s DNS tools and test from more than one network if propagation is in doubt. Do not request certificates until every name on the certificate resolves to this VPS and reaches the correct block.

Use a harmless PHP probe

Create a temporary file such as /var/www/site-a/public/health.php containing a minimal PHP response, request it through the domain, and remove it immediately after confirming execution. A probe proves that NGINX selected the intended root, connected to PHP-FPM and passed the correct script filename; it does not validate the application’s database, sessions or upload handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add HTTPS for every hostname

Obtain a certificate covering each hostname you actually serve, using an ACME client or certificate process supported by your distribution and certificate authority. Create an HTTPS block for each site with its certificate, private key, root, PHP location and any application-specific settings. Keep private keys readable only by the account that needs them.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Test SNI one domain at a time

Use a hostname-specific request such as:

curl -I --resolve site-a.example:443:203.0.113.10 https://site-a.example/
curl -I --resolve site-b.example:443:203.0.113.10 https://site-b.example/

The --resolve option pins the connection to the VPS while retaining the hostname used for SNI and certificate verification. Inspect the certificate and response for each domain separately. Also test the exact apex and www variants listed in each certificate.

Redirect HTTP only after HTTPS works

Once every HTTPS block responds correctly, change each port-80 block to a narrow redirect for its own names:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server {
    listen 80;
    server_name site-a.example www.site-a.example;
    return 301 https://site-a.example$request_uri;
}

Choose a canonical hostname deliberately; if both names should remain valid, redirect only the non-canonical one in a separate block. Test login callbacks, webhooks, uploads and any absolute URLs after enabling the redirect. Redirecting first can hide a broken certificate, wrong SNI match or incorrect application URL.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose shared or per-site PHP-FPM pools

A shared pool is the simplest arrangement: every site uses the same PHP-FPM worker account and socket. It consumes less memory and has fewer files to maintain, but a pool failure or poorly behaved workload affects all sites and file permissions are harder to isolate.

Per-site pools give each application a distinct Unix user, socket and worker limits. They reduce credential and failure blast radius and allow different PHP versions or limits where the operating system supports them. The trade-off is additional memory, configuration, monitoring and update work. Exact worker counts and memory limits must come from measurements of your applications and VPS, not a universal formula.

Criterion Shared pool Per-site pools
Memory use Lower baseline because workers are shared. Higher baseline as pools maintain separate workers.
Isolation Applications commonly share a worker account and execution boundary. Distinct users and sockets can separate applications and writable paths.
Failure blast radius A pool outage or exhaustion can affect every site using it. A failing pool is less likely to stop unrelated sites.
Operations Fewer pool files, sockets and alerts. More tuning, log review and lifecycle tasks.
Use when Sites are trusted, similar and the VPS is small. Sites have different owners, risk levels, traffic patterns or PHP requirements.

Point a site at its own pool

Define a pool with a unique user, group and listen socket, then set that socket in the site’s fastcgi_pass. Ensure the socket directory permissions allow NGINX to connect, reload PHP-FPM after validating its configuration, and test the site before moving on to the next pool. Never copy a socket path from another server without checking that it exists locally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One VPS or several?

Combining sites on one VPS saves the overhead of multiple operating systems and network endpoints, but all applications share CPU, memory, storage performance and the host’s maintenance window. Separate VPS instances cost more and require more patching, yet they isolate credentials, resource contention and outages.

Axis One VPS Separate VPS instances
Cost One base server and one set of infrastructure services. Several server bills and usually duplicated monitoring and backups.
Maintenance Centralized updates and configuration; a mistake can affect every site. Changes are contained but must be repeated and tracked.
Noisy-neighbor risk One busy application can consume shared resources. Resource contention is largely confined to each instance.
Credential isolation Requires careful users, permissions and pool boundaries. Network and operating-system boundaries provide stronger separation.
Recovery A host failure takes all sites offline unless backups or replicas are ready. One instance can fail while others remain available.

Choose one VPS when the applications are compatible and you can monitor and limit them. Split workloads when owners, compliance requirements, update schedules or resource profiles are materially different.

Harden and operate the multi-site server

Limit the attack surface

  • Allow only required inbound ports in the firewall, normally SSH, HTTP and HTTPS; restrict SSH administration by source network where practical.
  • Keep the operating system, NGINX, PHP, PHP-FPM and application dependencies patched.
  • Disable PHP execution in upload directories with an explicit location rule or application-supported layout.
  • Use least-privilege users and avoid granting the web worker unrestricted shell or database access.
  • Review enabled modules and remove sample files, installers and temporary probes.

Control requests and resources

Set request-body, timeout and upload limits to the needs of each application. Tune PHP-FPM worker limits, NGINX connection settings and operating-system limits from observed CPU, memory, latency and queue data. There is no safe universal value: an upload-heavy site and a mostly static site need different settings. Keep enough headroom for deploys, backups and traffic spikes.

Separate logs and monitor them

Use an access and error log per site so a failing application can be identified without wading through unrelated traffic. Configure log rotation before disks fill. Watch for repeated upstream errors, permission failures, unusual status-code spikes, PHP-FPM queue growth and storage exhaustion. Correlate timestamps across NGINX, PHP-FPM and application logs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Back up what is difficult to recreate

Back up databases, uploaded files, application configuration and the NGINX/PHP-FPM configuration. Store at least one copy outside the VPS and test restoration; a backup that has never been restored is only an assumption.

Troubleshoot by symptom

Symptom Likely checks Remedy
Every domain shows the same site Inspect server_name, DNS, the request’s Host header and the default server. Correct names and records, remove duplicates, and test with curl -H 'Host: ...'.
Unknown hosts expose a real site Check which block is default for port 80 or 443. Create an intentional default server that returns a controlled response.
502 Bad Gateway Check PHP-FPM service state, the exact socket/TCP address and socket permissions. Start the matching service, correct fastcgi_pass, and reload after nginx -t.
PHP downloads as text Confirm the PHP location is loaded and that requests reach the intended block. Fix the location or include, verify fastcgi_pass, then retest a temporary probe.
404 for existing files Compare root with the actual path and inspect try_files. Correct the document root, file permissions or application front-controller rule.
403 Forbidden Check parent-directory traversal, file ownership, mode bits and mandatory access controls. Grant read/traverse access without making the whole tree writable.
POST or login fails Review FastCGI parameters, request limits, session storage and application logs. Use the maintained parameter include and confirm REQUEST_METHOD, CONTENT_TYPE and CONTENT_LENGTH reach PHP.
Certificate for the wrong domain Test each hostname separately and inspect SNI, certificate names and the 443 server_name. Install a certificate covering that name and correct the matching HTTPS block.
Redirect loop Compare NGINX redirects with the application’s trusted-proxy and HTTPS settings. Keep one canonical redirect and configure the application to recognize the HTTPS scheme.

Deployment checklist

  1. Install supported NGINX, PHP and PHP-FPM packages and confirm the active service and socket.
  2. Create a separate document root, ownership model, writable directories and logs for each site.
  3. Add one port-80 server block per domain, including every apex and www name you intend to serve.
  4. Use a maintained FastCGI include, an explicit SCRIPT_FILENAME and the verified PHP-FPM endpoint.
  5. Choose static-file or application-specific routing; do not pass arbitrary paths to PHP.
  6. Run nginx -t, reload, and test each hostname with an explicit Host header.
  7. Point A and AAAA records to the VPS, verify resolution, and test the real names.
  8. Install certificates and HTTPS blocks, then test SNI for every hostname.
  9. Enable HTTP-to-HTTPS redirects only after HTTPS, logins, uploads and callbacks work.
  10. Set least-privilege permissions, firewall rules, updates, log rotation, resource limits and tested backups.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.