Migrating NGINX Websites to ServBay's Caddy Server
ServBay is a powerful local web development environment that integrates several popular web servers, including Caddy, NGINX, and Apache. ServBay comes pre-configured with commonly used URL rewrite rules for these servers—especially Caddy and NGINX—greatly simplifying configuration tasks for developers.
This detailed guide walks you through the process of seamlessly migrating your existing NGINX websites to the Caddy server built into ServBay. Using popular PHP frameworks like Laravel and CMS platforms like WordPress as examples, you'll see how straightforward the migration process can be.
Comprehensive Web Server Support in ServBay
ServBay offers full support for Caddy, NGINX, and Apache. You can easily switch the default web server based on project requirements. For more details, refer to the How to Switch the Default Web Server documentation.
Overview
Migrating a website from one web server to another typically involves transferring configuration files and site assets. In ServBay, the migration process to Caddy is extremely straightforward. For the majority of PHP-based frameworks and CMSs—including Laravel, WordPress, Symfony, CodeIgniter, Drupal, Joomla, and others—ServBay offers out-of-the-box support. In most cases, there’s no need to manually create or edit Caddy configuration files. ServBay will automatically generate the necessary Caddyfile settings based on your website configurations set within the GUI.
Pre-Migration Checklist
Before starting any migration, make sure you complete the following steps:
- Backup Website Files: Create a full backup of all files and folders in your website’s root directory.
- Backup Databases: Export and save the databases used by your site (e.g., MySQL, PostgreSQL, MongoDB). ServBay includes built-in database management tools but also supports manual backups.
- Install ServBay: Ensure ServBay is successfully installed and running on your macOS system.
- Confirm File Location: Place your website files in ServBay’s default web root at
/Applications/ServBay/www
or in a subdirectory. For example, if your project is namedmyproject
, place it in/Applications/ServBay/www/myproject
.
How Caddy Works in ServBay
Understanding how ServBay manages Caddy configurations is crucial for a smooth migration. Unlike manually editing the Caddyfile, ServBay provides a graphical user interface (GUI) for website addition and configuration. When you add a new site and select Caddy as the web server, ServBay automatically generates and manages Caddyfile snippets based on your domain, website root, PHP version, and other settings. These snippets are included in ServBay’s main Caddyfile so your website runs as expected.
This means that simply adding your website through the ServBay GUI completes all required Caddy configuration—there’s no need to manually edit any .caddyfile
or similar text files.
Migration Steps
Migrating an NGINX website to ServBay’s Caddy server is very straightforward:
- Launch ServBay: Make sure the ServBay application is running.
- Locate Website Files: Copy or move your NGINX website files—including all application code, images, CSS, JS, etc.—into a new folder under ServBay's web root, such as
/Applications/ServBay/www/your-site-name
. - Add Site via ServBay GUI:
- Open the ServBay application.
- Navigate to the “Websites” section.
- Click the “Add Website” button.
- Complete the site information:
- Domain: Enter the local domain you want, e.g.,
your-site-name.servbay.demo
. - Website Root: Select the folder from step 2, e.g.,
/Applications/ServBay/www/your-site-name
. - Web Server: Choose
Caddy
. - PHP Version: Select the PHP version your site requires.
- Domain: Enter the local domain you want, e.g.,
- Click “Save” or “Create.”
- Verify the Site: ServBay will automatically add the new domain to your local hosts file and configure Caddy. In your browser, visit the local domain you set up (e.g.,
http://your-site-name.servbay.demo
) and check that your website loads properly. - Database Configuration: If your site uses a database, ensure the corresponding database service (such as MySQL or PostgreSQL) is running in ServBay. Then update your site’s config files with the correct database connection info (database host is usually
127.0.0.1
orlocalhost
; use your chosen username and password).
Example: Migrating a Laravel Website
Typical NGINX Configuration (For Reference)
Here’s a sample NGINX config file for a Laravel site. It demonstrates how to configure the root directory, entry file (index.php
), and PHP FastCGI handling in NGINX:
server {
listen 80;
server_name laravel.servbay.demo; # Example domain with ServBay branding
root /Applications/ServBay/www/laravel/public; # Points to Laravel's public directory
index index.php index.html index.htm;
location / {
# Try to serve files or directories; fallback to index.php if not found
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
# Configure PHP FastCGI processing
include fastcgi_params;
# ServBay’s default PHP-CGI socket path
fastcgi_pass unix:/Applications/ServBay/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
# Deny access to hidden files
deny all;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Equivalent Caddy Configuration in ServBay (Automatically Generated, No Manual Editing Required)
No Manual Caddyfile Configuration Needed
With ServBay, you do not need to manually create or edit a Caddyfile to achieve the above functionality. The ServBay GUI will automatically generate the necessary Caddy configurations when you add a site. The following Caddy config is provided for illustrative purposes only, so you can understand how ServBay translates similar NGINX settings behind the scenes.
Below is a simplified version of the Caddy configuration snippet that ServBay would automatically generate for the above Laravel site (the actual config may contain more details for extended functionality):
# This configuration is managed automatically by ServBay
laravel.servbay.demo {
# Set the site root
root * /Applications/ServBay/www/laravel/public
# Configure PHP FastCGI, pointing to ServBay’s PHP-CGI socket
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
# Enable file serving
file_server
# Define a matcher for non-static files
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
# Rewrite non-static requests to index.php
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Steps to Migrate a Laravel Site:
- Copy your Laravel project files to
/Applications/ServBay/www/laravel
. - Make sure the
laravel/public
directory is set as the site’s entry point. - Add a new site in the ServBay GUI: set the domain to
laravel.servbay.demo
, the root to/Applications/ServBay/www/laravel/public
, and chooseCaddy
as the web server. - Configure the correct database connection information in your Laravel
.env
file. - Test the site at
http://laravel.servbay.demo
.
Example: Migrating a WordPress Website
Typical NGINX Configuration (For Reference)
Below is a typical NGINX config file for a WordPress website:
server {
listen 80;
server_name wordpress.servbay.demo; # Example domain with ServBay branding
root /Applications/ServBay/www/wordpress; # Points to the WordPress installation directory
index index.php index.html index.htm;
location / {
# WordPress permalink rules
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
# Configure PHP FastCGI processing
include fastcgi_params;
# ServBay’s default PHP-CGI socket path
fastcgi_pass unix:/Applications/ServBay/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
# Deny access to hidden files
deny all;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Equivalent Caddy Configuration in ServBay (Automatically Generated, No Manual Editing Required)
No Manual Caddyfile Configuration Needed
Likewise, for WordPress, ServBay’s GUI will handle all the Caddy configuration for you. The example below just illustrates how ServBay enables permalinks and similar features for WordPress.
The following is a theoretical Caddy configuration snippet that ServBay would automatically generate for the above WordPress site:
# This configuration is managed automatically by ServBay
wordpress.servbay.demo {
# Set the site root
root * /Applications/ServBay/www/wordpress
# Configure PHP FastCGI
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
# Enable file serving
file_server
# Define a matcher for non-static files
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
# Rewrite non-static requests to index.php to support clean permalinks
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Steps to Migrate a WordPress Site:
- Copy your WordPress files to
/Applications/ServBay/www/wordpress
. - Add a new site in the ServBay GUI: set the domain to
wordpress.servbay.demo
, website root to/Applications/ServBay/www/wordpress
, and chooseCaddy
as the web server. - Update database connection information in the WordPress
wp-config.php
file. - Test the site at
http://wordpress.servbay.demo
. If you encounter permalink issues, note that ServBay already handles the rewrite rules—no extra config is necessary. Just check the “Settings” -> “Permalinks” section in your WordPress admin.
Additional Notes
- Database Connections: After migration, always update your website code’s database connection details to point to the database service running in ServBay.
- Environment Variables: If your app depends on specific environment variables, ensure they are set in the ServBay environment (for example, via PHP
.env
files or ServBay’s configuration options). - Complex NGINX Configurations: The examples here cover standard Laravel and WordPress setups. If your NGINX config includes complex custom rules, specialized modules, or unconventional settings, ServBay’s automatic configuration may not cover everything. In that case, consult the Caddy documentation, and use any custom configuration entry points ServBay offers (if available), or understand how ServBay’s auto-generation logic works to implement advanced features. For most common scenarios, however, ServBay’s automation should be sufficient.
- HTTPS/SSL: ServBay supports HTTPS for local sites. You can use ServBay’s User CA or Public CA to generate and trust local SSL certificates—manual Caddy TLS config isn’t needed.
Conclusion
Migrating NGINX websites to ServBay’s Caddy server is a streamlined process thanks to ServBay’s automated Caddy configuration management. For popular applications like Laravel or WordPress, you simply place your files in the right directory and add the site via ServBay’s GUI. ServBay handles all URL rewriting, PHP FastCGI configuration, and more—allowing you to quickly and efficiently run your sites on Caddy in your local environment.