Chuyển .htaccess sang nginx / Caddy, kiểm tra cấu hình nginx
Chuyển .htaccess của Apache thành khối server nginx và Caddyfile, lint nginx.conf tìm lỗi thường gặp, sinh cấu hình WordPress, Laravel, SPA, proxy.
Kết quả
Bấm “Chạy” để xem kết quả.
convert (mặc định) chuyển file .htaccess thành khối server của nginx và Caddyfile: mod_rewrite (RewriteCond / RewriteRule với cờ L, R=301, NC, QSA, QSD, F, G, OR, RewriteBase, tham chiếu %N), mẫu front controller (→ try_files), chuyển hướng HTTPS và www, Redirect / RedirectMatch, ErrorDocument, DirectoryIndex, Options, Header, mod_expires (→ map theo content type), mod_deflate, Deny / Allow / Require, <Files> / <FilesMatch>, basic auth, LimitRequestBody, ServerSignature. Mỗi chỉ thị có confidence (high / medium / low / none) và ghi chú; cấu hình PHP (php_value, php_flag) được chuyển thành đoạn cấu hình pool PHP-FPM. Kết quả qua được nginx -t với các chỉ thị được hỗ trợ.
lint kiểm tra tĩnh cấu hình nginx: thiếu ngoặc, thiếu dấu chấm phẩy, if trong location ("if is evil"), lỗ hổng alias path traversal (location không có / + alias có /), add_header ở khối con làm mất header của khối cha, proxy_pass có URI trong location regex, biến không có resolver, giao thức TLS cũ và cipher yếu, listen 443 thiếu ssl, cú pháp listen … http2 đã lỗi thời, CRLF injection qua $uri trong redirect, location PHP không neo $ / thiếu try_files, autoindex, server_name trùng, thiếu HSTS / header bảo mật và server_tokens.
generate sinh cấu hình nginx và Caddy cho site static, spa, wordpress, laravel, php hoặc reverse-proxy: chuyển HTTP → HTTPS, chuyển www / tên miền gốc, đường dẫn chứng chỉ Let’s Encrypt, gzip (brotli tuỳ chọn), cache file tĩnh và header bảo mật. Hãy chạy nginx -t hoặc caddy validate trước khi áp dụng.
Dùng trong code của bạn
curl -X POST "https://apibox.io.vn/v1/webserver-config" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"htaccess":"RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n","server_name":"example.com","root":"/var/www/example"}'const res = await fetch('https://apibox.io.vn/v1/webserver-config', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"htaccess": "RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n",
"server_name": "example.com",
"root": "/var/www/example"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/webserver-config",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"htaccess": "RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n", "server_name": "example.com", "root": "/var/www/example"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/webserver-config');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"htaccess":"RewriteEngine On\\nRewriteCond %{HTTPS} off\\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\\nRewriteRule ^old-page$ /new-page [R=301,L]\\nRewriteCond %{REQUEST_FILENAME} !-f\\nRewriteCond %{REQUEST_FILENAME} !-d\\nRewriteRule . /index.php [L]\\nphp_value upload_max_filesize 64M\\n","server_name":"example.com","root":"/var/www/example"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Tài liệu API → Nhận API key miễn phí
Hỏi đáp
Mọi luật mod_rewrite đều chuyển được?
Các mẫu phổ biến được chuyển với độ tin cậy cao; chuỗi phức tạp (nhiều điều kiện, [P], [S], [C]) được đánh dấu low kèm ghi chú. Luôn chạy nginx -t và thử các URL quan trọng.
Dòng php_value đi đâu?
Không vào nginx: kết quả có các dòng php_value / php_flag cho pool PHP-FPM (hoặc đặt trong php.ini / .user.ini).
Lint có đọc file include không?
Không: hãy gửi toàn bộ nội dung cấu hình. Đây là kiểm tra tĩnh, không phải nginx -t.