How to Migrate NGINX Websites to Caddy
ServBay comes with Caddy, NGINX, and Apache as web servers, and has preconfigured URL Rewrite rules for both Caddy and NGINX, so users typically do not need to configure Rewrite rules separately. This article will detail how to migrate an NGINX website to the Caddy server bundled with ServBay, using Laravel and WordPress as examples.
Support for NGINX and Apache
ServBay now supports NGINX, please refer to How to Switch Default Web Server to NGINX.
Overview
Migrating a website involves transferring the existing configuration and files to a new server environment. ServBay supports users in using Caddy as a web server, with ready-to-go support for most PHP frameworks and CMS systems without the need for additional configuration of Rewrite rules.
Preparation Before Migration
Before starting the migration, ensure you have backed up all website files and databases. Various issues may arise during the migration process, so backups are crucial.
Migrating a Laravel Website
NGINX Configuration
Here is a typical NGINX configuration file for a Laravel website:
server {
listen 80;
server_name laravel.demo;
root /Applications/ServBay/www/laravel/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/Applications/ServBay/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Caddy Configuration
Important Note
In ServBay, the Rewrite rules and PHP handling rules are already preconfigured, users do not need to manually write configuration files.
Here is a theoretical Caddy configuration example for comparison and understanding:
laravel.demo {
root * /Applications/ServBay/www/laravel/public
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
file_server
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Migrating a WordPress Website
NGINX Configuration
Here is a typical NGINX configuration file for a WordPress website:
server {
listen 80;
server_name wordpress.demo;
root /Applications/ServBay/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/Applications/ServBay/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Caddy Configuration
Important Note
In ServBay, the Rewrite rules and PHP handling rules are already preconfigured, users do not need to manually write configuration files.
Here is a theoretical Caddy configuration example for comparison and understanding:
wordpress.demo {
root * /Applications/ServBay/www/wordpress
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
file_server
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Conclusion
Migrating an NGINX website to ServBay's Caddy server is very straightforward, requiring no configuration changes; users simply need to add their website in ServBay. The Caddy configuration syntax is simple and readable, and ServBay has already preconfigured the Rewrite rules and PHP handling. Through this article, you can understand how to migrate Laravel and WordPress websites to Caddy.