mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
chore: clean up Railway deployment - remove debug code
This commit is contained in:
+1
-4
@@ -25,10 +25,7 @@ COPY --from=frontend /usr/share/nginx/html /usr/share/nginx/html
|
||||
WORKDIR /app
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
# nginx 配置模板(使用 $PORT 变量)
|
||||
COPY railway/nginx.conf.template /etc/nginx/nginx.conf.template
|
||||
|
||||
# 启动脚本
|
||||
# 启动脚本(包含 nginx 配置生成)
|
||||
COPY railway/start.sh /app/start.sh
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
server {
|
||||
listen ${PORT};
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Gzip
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml;
|
||||
|
||||
# SPA 路由
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API 代理到后端
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8081/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_connect_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
proxy_read_timeout 300s;
|
||||
}
|
||||
|
||||
# 健康检查
|
||||
location /health {
|
||||
return 200 'OK';
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
+7
-48
@@ -1,30 +1,25 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# 默认端口(Railway 会设置 PORT=8080)
|
||||
# Railway 会设置 PORT 环境变量
|
||||
export PORT=${PORT:-8080}
|
||||
echo "🚀 Starting NOFX on port $PORT..."
|
||||
|
||||
# 生成加密密钥(如果没有设置)
|
||||
if [ -z "$RSA_PRIVATE_KEY" ]; then
|
||||
echo "🔐 Generating RSA key..."
|
||||
export RSA_PRIVATE_KEY=$(openssl genrsa 2048 2>/dev/null)
|
||||
fi
|
||||
|
||||
if [ -z "$DATA_ENCRYPTION_KEY" ]; then
|
||||
echo "🔐 Generating data encryption key..."
|
||||
export DATA_ENCRYPTION_KEY=$(openssl rand -base64 32)
|
||||
fi
|
||||
|
||||
# 生成 nginx 配置(直接写入,避免 envsubst 问题)
|
||||
echo "📝 Generating nginx config for port $PORT..."
|
||||
# 生成 nginx 配置
|
||||
cat > /etc/nginx/http.d/default.conf << NGINX_EOF
|
||||
server {
|
||||
listen $PORT;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript;
|
||||
|
||||
@@ -48,51 +43,15 @@ server {
|
||||
}
|
||||
}
|
||||
NGINX_EOF
|
||||
echo "✅ Nginx config generated"
|
||||
cat /etc/nginx/http.d/default.conf
|
||||
|
||||
# 启动后端(后台运行,端口 8081 避免与 nginx 冲突)
|
||||
echo "🔧 Starting backend on port 8081..."
|
||||
# 启动后端(端口 8081)
|
||||
API_SERVER_PORT=8081 /app/nofx &
|
||||
BACKEND_PID=$!
|
||||
sleep 2
|
||||
|
||||
# 等待后端启动
|
||||
sleep 3
|
||||
|
||||
# 检查后端是否启动成功
|
||||
if ! kill -0 $BACKEND_PID 2>/dev/null; then
|
||||
echo "❌ Backend failed to start"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Backend started (PID: $BACKEND_PID)"
|
||||
|
||||
# 删除默认的 nginx 配置避免冲突
|
||||
rm -f /etc/nginx/http.d/default.conf.bak 2>/dev/null || true
|
||||
|
||||
# 测试 nginx 配置
|
||||
echo "🔍 Testing nginx config..."
|
||||
nginx -t 2>&1
|
||||
|
||||
# 检查前端文件是否存在
|
||||
echo "📁 Checking frontend files..."
|
||||
ls -la /usr/share/nginx/html/ | head -5
|
||||
|
||||
# 启动 nginx(后台先测试)
|
||||
echo "🌐 Starting nginx on port $PORT..."
|
||||
# 启动 nginx(后台)
|
||||
nginx
|
||||
|
||||
# 等待 nginx 启动
|
||||
sleep 1
|
||||
echo "✅ NOFX started successfully"
|
||||
|
||||
# 测试 nginx 是否响应
|
||||
echo "🔍 Testing nginx response..."
|
||||
wget -q -O - http://127.0.0.1:$PORT/health || echo "❌ Health check failed"
|
||||
|
||||
# 检查 nginx 进程
|
||||
echo "📋 Nginx processes:"
|
||||
ps aux | grep nginx
|
||||
|
||||
# 保持前台运行
|
||||
echo "✅ All services started, keeping container alive..."
|
||||
# 保持容器运行
|
||||
tail -f /dev/null
|
||||
|
||||
Reference in New Issue
Block a user