Docker化部署:多阶段构建 + docker-compose 编排;删除开发/内置服务器脚本;安全加固
This commit is contained in:
1 parent
044e526c80
commit
af98618810
15 files changed
+424
-127
No files matched your search
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# 从环境变量生成 .env
|
||||
if [ ! -f /var/www/.env ]; then
|
||||
echo ">>> Generating .env from environment..."
|
||||
cat > /var/www/.env << EOF
|
||||
APP_ENV=${APP_ENV:-production}
|
||||
APP_DEBUG=${APP_DEBUG:-false}
|
||||
APP_URL=${APP_URL:-http://localhost}
|
||||
|
||||
DB_HOST=${DB_HOST:-db}
|
||||
DB_PORT=${DB_PORT:-3306}
|
||||
DB_NAME=${DB_NAME:-card_auth}
|
||||
DB_USER=${DB_USER:-card_auth}
|
||||
DB_PASS=${DB_PASS:-}
|
||||
DB_PREFIX=${DB_PREFIX:-ca_}
|
||||
|
||||
JWT_SECRET=${JWT_SECRET:-}
|
||||
|
||||
PAYMENT_TYPE=${PAYMENT_TYPE:-epay}
|
||||
PAYMENT_API_URL=${PAYMENT_API_URL:-}
|
||||
PAYMENT_APP_ID=${PAYMENT_APP_ID:-}
|
||||
PAYMENT_APP_KEY=${PAYMENT_APP_KEY:-}
|
||||
EOF
|
||||
chmod 600 /var/www/.env
|
||||
echo ">>> .env generated"
|
||||
fi
|
||||
|
||||
# 等待 MySQL 就绪
|
||||
echo ">>> Waiting for MySQL at ${DB_HOST}:${DB_PORT}..."
|
||||
until nc -z ${DB_HOST} ${DB_PORT} 2>/dev/null; do
|
||||
sleep 2
|
||||
done
|
||||
echo ">>> MySQL is ready"
|
||||
|
||||
# 启动 Supervisor (Nginx + PHP-FPM)
|
||||
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
@@ -0,0 +1,53 @@
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
server_name _;
|
||||
|
||||
root /var/www/public;
|
||||
index index.php index.html;
|
||||
|
||||
client_max_body_size 20M;
|
||||
|
||||
# 前端 SPA fallback
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API 路由
|
||||
location /api/ {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
# PHP-FPM
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
fastcgi_param HTTP_AUTHORIZATION $http_authorization;
|
||||
fastcgi_hide_header X-Powered-By;
|
||||
}
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# 安全:禁止访问敏感文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
}
|
||||
location ~* \.(env|sql|log|md|gitignore)$ {
|
||||
deny all;
|
||||
}
|
||||
location ~* ^/(storage/cache|storage/logs)/ {
|
||||
deny all;
|
||||
}
|
||||
|
||||
# 禁止访问源代码目录
|
||||
location ~* ^/(app|config|routes|database|vendor)/ {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
logfile=/dev/stdout
|
||||
logfile_maxbytes=0
|
||||
|
||||
[program:php-fpm]
|
||||
command=php-fpm -F
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
|
||||
[program:nginx]
|
||||
command=nginx -g "daemon off;"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
Reference in new issue
Block a user