Как перенести сайт NGINX на ServBay
Веб-сервером, поставляемым с ServBay, является Caddy, известный своей простой конфигурацией и автоматическим HTTPS. ServBay уже заранее настроил правила переписывания (Rewrite Rules), поэтому пользователям обычно не требуется дополнительных настроек. В этой статье подробно описывается, как перенести сайт с NGINX на ServBay, с примерами на Laravel и WordPress.
Обзор
Перенос сайта включает в себя перенос существующих конфигураций и файлов в новую серверную среду. ServBay использует Caddy в качестве веб-сервера, и для большинства PHP-фреймворков и CMS-систем ServBay работает "из коробки", без необходимости дополнительных настроек правил переписывания.
Подготовка к переносу
Перед началом переноса убедитесь, что у вас есть резервные копии всех файлов сайта и базы данных. В процессе переноса могут возникнуть различные проблемы, поэтому резервное копирование очень важно.
Перенос сайта Laravel
Конфигурация NGINX
Ниже приведен типичный конфигурационный файл NGINX для сайта на Laravel:
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
Важное замечание
В ServBay правила переписывания и обработка PHP уже настроены по умолчанию, пользователям не нужно вручную писать конфигурационные файлы.
Ниже приведен теоретический пример конфигурации Caddy для сравнения и понимания:
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
Перенос сайта WordPress
Конфигурация NGINX
Ниже приведен типичный конфигурационный файл NGINX для сайта на WordPress:
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
Важное замечание
В ServBay правила переписывания и обработка PHP уже настроены по умолчанию, пользователям не нужно вручную писать конфигурационные файлы.
Ниже приведен теоретический пример конфигурации Caddy для сравнения и понимания:
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
Резюме
Перенос сайта с NGINX на сервер Caddy в ServBay очень прост, не требует никаких изменений конфигурации и пользователям нужно только добавить сайт в ServBay. Синтаксис конфигурационных файлов Caddy простой и легко читаемый, в ServBay уже настроены правила переписывания и обработка PHP, пользователям обычно не требуется дополнительных настроек. На примере этой статьи вы можете понять, как перенести сайт Laravel и WordPress в ServBay.