-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
142 lines (118 loc) · 3.55 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# deploy.sh
echo "Starting frontend deployment..."
# Define paths
FRONTEND_DIR="/home/ubuntu/Pilo-frontend"
DOMAIN="www.pilo.life"
BUILD_DIR="$FRONTEND_DIR/dist"
# Create Nginx configuration for HTTP first
echo "Creating initial HTTP Nginx configuration..."
sudo tee /etc/nginx/nginx.conf > /dev/null << EOL
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# MIME Types
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Gzip Settings
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# HTTP server
server {
listen 80;
server_name $DOMAIN;
# Root directory
root $BUILD_DIR;
index index.html;
# Static file serving
location / {
try_files \$uri \$uri/ /index.html;
expires 30d;
add_header Cache-Control "public, no-transform";
}
# Assets
location /assets {
expires 1y;
add_header Cache-Control "public, no-transform";
}
# API proxy
location /api/ {
proxy_pass http://api.pilo.life/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host api.pilo.life;
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
}
EOL
# Build frontend
echo "Building frontend..."
if [ -d "$FRONTEND_DIR" ]; then
cd "$FRONTEND_DIR"
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
echo "Creating production build..."
npm run build
else
echo "❌ Frontend directory not found at $FRONTEND_DIR"
exit 1
fi
# Test Nginx configuration
echo "Testing Nginx configuration..."
sudo nginx -t
if [ $? -eq 0 ]; then
echo "Nginx configuration is valid"
sudo systemctl restart nginx
else
echo "❌ Nginx configuration is invalid"
exit 1
fi
# Final checks
echo "Performing final checks..."
if systemctl is-active --quiet nginx; then
echo "✅ Nginx is running"
else
echo "❌ Nginx failed to start"
fi
echo "Testing HTTP endpoint..."
curl -I http://$DOMAIN/
echo "Deployment complete!"
echo "You can monitor logs with:"
echo "- Nginx access logs: sudo tail -f /var/log/nginx/access.log"
echo "- Nginx error logs: sudo tail -f /var/log/nginx/error.log"
# Show status
echo -e "\nService Status:"
sudo systemctl status nginx --no-pager
echo -e "\nIMPORTANT: Your site is now running on HTTP."
echo "To enable HTTPS, follow these steps:"
echo "1. Make sure port 80 is open in your security group"
echo "2. Install certbot if not already installed:"
echo " sudo apt-get update"
echo " sudo apt-get install certbot python3-certbot-nginx"
echo "3. Run: sudo certbot --nginx -d $DOMAIN"
echo "4. Follow the prompts to configure HTTPS"
echo "5. Certbot will automatically modify the Nginx configuration for HTTPS"