Skip to content

Commit 75737f3

Browse files
committed
Fix Nginx server block configuration for Let's Encrypt: ensure proper server_name directive and site enabling before certbot runs
1 parent 4a3a4fc commit 75737f3

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

.github/workflows/deploy-backend.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ jobs:
155155
156156
# Set up Nginx reverse proxy with HTTPS
157157
if [ -n "${{ secrets.DOMAIN_NAME }}" ]; then
158-
# Check if Let's Encrypt certificate exists
159-
if [ -f "/etc/letsencrypt/live/${{ secrets.DOMAIN_NAME }}/fullchain.pem" ]; then
160-
echo "Using Let's Encrypt certificate for ${{ secrets.DOMAIN_NAME }}"
161-
# Let's Encrypt configuration (certbot will modify this)
162-
sudo tee /etc/nginx/sites-available/maizebus-backend > /dev/null <<EOF
158+
# Create initial Nginx configuration for Let's Encrypt
159+
echo "Setting up Nginx configuration for ${{ secrets.DOMAIN_NAME }}"
160+
sudo tee /etc/nginx/sites-available/maizebus-backend > /dev/null <<EOF
161+
# HTTP server - will be modified by certbot
163162
server {
164163
listen 80;
165164
server_name ${{ secrets.DOMAIN_NAME }};
@@ -177,6 +176,15 @@ jobs:
177176
}
178177
}
179178
EOF
179+
180+
# Enable the site and test Nginx configuration
181+
sudo ln -sf /etc/nginx/sites-available/maizebus-backend /etc/nginx/sites-enabled/
182+
sudo nginx -t && sudo systemctl reload nginx
183+
184+
# Check if Let's Encrypt certificate exists
185+
if [ -f "/etc/letsencrypt/live/${{ secrets.DOMAIN_NAME }}/fullchain.pem" ]; then
186+
echo "Using existing Let's Encrypt certificate for ${{ secrets.DOMAIN_NAME }}"
187+
# Certbot will have already modified the configuration
180188
else
181189
echo "Using self-signed certificate with EC2 domain (Let's Encrypt failed)"
182190
# Self-signed certificate configuration with EC2 domain

0 commit comments

Comments
 (0)