Docker化部署:多阶段构建 + docker-compose 编排;删除开发/内置服务器脚本;安全加固
This commit is contained in:
1 parent
044e526c80
commit
af98618810
15 files changed
+424
-127
No files matched your search
@@ -1,4 +1,6 @@
|
||||
APP_DEBUG=true
|
||||
# 环境模式: development | production
|
||||
APP_ENV=production
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://your-domain.com
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
|
||||
@@ -5,9 +5,19 @@
|
||||
*/
|
||||
|
||||
// 错误报告设置
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '0');
|
||||
$isDev = (getenv('APP_ENV') ?: 'production') === 'development';
|
||||
$isDebug = filter_var(getenv('APP_DEBUG') ?: 'false', FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
error_reporting($isDev ? E_ALL : E_ALL & ~E_DEPRECATED & ~E_STRICT);
|
||||
ini_set('display_errors', $isDev ? '1' : '0');
|
||||
ini_set('log_errors', '1');
|
||||
ini_set('error_log', STORAGE_PATH . '/logs/error.log');
|
||||
|
||||
// 生产环境隐藏 PHP 版本
|
||||
if (!$isDev) {
|
||||
ini_set('expose_php', '0');
|
||||
header_remove('X-Powered-By');
|
||||
}
|
||||
|
||||
// 定义基础路径
|
||||
define('BASE_PATH', dirname(__DIR__));
|
||||
@@ -60,10 +70,10 @@ try {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'code' => 500,
|
||||
'message' => config('app.debug') ? $e->getMessage() : '服务器内部错误',
|
||||
'message' => $isDebug ? $e->getMessage() : '服务器内部错误',
|
||||
'data' => null,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
if (config('app.debug')) {
|
||||
if ($isDebug) {
|
||||
error_log($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP内置服务器路由器
|
||||
* 用法: php -S 0.0.0.0:8080 router.php
|
||||
*/
|
||||
|
||||
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
|
||||
// 静态文件直接返回
|
||||
if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) {
|
||||
$filePath = __DIR__ . '/public' . $uri;
|
||||
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
||||
$mimeTypes = [
|
||||
'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png', 'gif' => 'image/gif',
|
||||
'webp' => 'image/webp', 'svg' => 'image/svg+xml',
|
||||
'css' => 'text/css', 'js' => 'application/javascript',
|
||||
'json' => 'application/json', 'ico' => 'image/x-icon',
|
||||
];
|
||||
header('Content-Type: ' . ($mimeTypes[$ext] ?? 'application/octet-stream'));
|
||||
header('Content-Length: ' . filesize($filePath));
|
||||
header('Cache-Control: public, max-age=31536000');
|
||||
readfile($filePath);
|
||||
exit;
|
||||
}
|
||||
|
||||
// API 请求走后端入口
|
||||
if (str_starts_with($uri, '/api/')) {
|
||||
require_once __DIR__ . '/public/index.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 非 API 请求返回前端 SPA 入口(index.html),前端 Vue Router 负责渲染路由
|
||||
$indexHtml = __DIR__ . '/public/index.html';
|
||||
if (file_exists($indexHtml)) {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
readfile($indexHtml);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 兜底:无法处理
|
||||
http_response_code(404);
|
||||
echo 'Not Found';
|
||||
exit;
|
||||
Whitespace-only changes.
Reference in new issue
Block a user