Cách Di Chuyển Trang Web Apache Sang ServBay
Máy chủ web đi kèm với ServBay là Caddy, nổi tiếng với cấu hình đơn giản và tự động HTTPS. Caddy đã được cấu hình sẵn các quy tắc Rewrite, người dùng thường không cần phải cấu hình thêm quy tắc Rewrite. Bài viết này sẽ chi tiết hướng dẫn cách di chuyển trang web Apache sang ServBay, lấy ví dụ từ Laravel và WordPress.
Tổng Quan
Di chuyển trang web bao gồm việc chuyển các cấu hình hiện có và tệp dữ liệu sang môi trường máy chủ mới. ServBay sử dụng Caddy làm máy chủ web, đối với hầu hết các khung PHP và hệ thống CMS, ServBay đã sẵn sàng sử dụng, không cần cấu hình thêm các quy tắc Rewrite.
Chuẩn Bị Trước Khi Di Chuyển
Trước khi bắt đầu di chuyển, hãy đảm bảo bạn đã sao lưu tất cả các tệp và cơ sở dữ liệu của trang web. Trong quá trình di chuyển có thể gặp nhiều vấn đề, do đó sao lưu rất quan trọng.
Di Chuyển Trang Web Laravel
Cấu Hình Apache
Dưới đây là một tệp cấu hình Apache điển hình cho trang web Laravel:
<VirtualHost *:80>
ServerName laravel.demo
DocumentRoot /Applications/ServBay/www/laravel/public
<Directory /Applications/ServBay/www/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/Applications/ServBay/tmp/php-cgi.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
2
3
4
5
6
7
8
9
10
11
12
13
14
Cấu Hình Caddy
Quan Trọng
Trong ServBay, quy tắc Rewrite và xử lý PHP đã được cấu hình sẵn, người dùng không cần phải tự viết tệp cấu hình.
Dưới đây là ví dụ cấu hình Caddy lý thuyết để so sánh và hiểu:
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
Di Chuyển Trang Web WordPress
Cấu Hình Apache
Dưới đây là một tệp cấu hình Apache điển hình cho trang web WordPress:
<VirtualHost *:80>
ServerName wordpress.demo
DocumentRoot /Applications/ServBay/www/wordpress
<Directory /Applications/ServBay/www/wordpress>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/Applications/ServBay/tmp/php-cgi.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
2
3
4
5
6
7
8
9
10
11
12
13
14
Cấu Hình Caddy
Quan Trọng
Trong ServBay, quy tắc Rewrite và xử lý PHP đã được cấu hình sẵn, người dùng không cần phải tự viết tệp cấu hình.
Dưới đây là ví dụ cấu hình Caddy lý thuyết để so sánh và hiểu:
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
Tổng Kết
Việc di chuyển trang web Apache sang máy chủ Caddy của ServBay rất đơn giản, không cần phải thực hiện bất kỳ thay đổi cấu hình nào, người dùng chỉ cần thêm trang web vào ServBay là xong. Cú pháp tệp cấu hình của Caddy đơn giản và dễ đọc, ServBay đã cấu hình sẵn các quy tắc Rewrite và xử lý PHP, người dùng thường không cần phải cấu hình thêm. Qua bài viết này, bạn có thể hiểu được cách di chuyển trang web Laravel và WordPress sang ServBay.