Skip to content

Commit f3aef88

Browse files
xkcodingclaude
andcommitted
fix: 修复 nginx 配置 heredoc 缩进问题
heredoc 中的内容缩进被保留导致 nginx 配置语法错误 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3f26287 commit f3aef88

1 file changed

Lines changed: 72 additions & 78 deletions

File tree

.github/workflows/production-deploy.yml

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -143,84 +143,78 @@ jobs:
143143
# 删除可能存在的错误目录,创建 nginx SSL 配置文件
144144
rm -rf /opt/myblog/nginx-ssl.conf
145145
cat > /opt/myblog/nginx-ssl.conf << 'NGINX_CONF'
146-
# HTTP - 重定向到 HTTPS
147-
server {
148-
listen 80;
149-
server_name xkcoding.com www.xkcoding.com blog.xkcoding.com;
150-
151-
location /.well-known/acme-challenge/ {
152-
root /usr/share/nginx/html;
153-
}
154-
155-
location / {
156-
return 301 https://$server_name$request_uri;
157-
}
158-
}
159-
160-
# HTTPS
161-
server {
162-
listen 443 ssl;
163-
server_name xkcoding.com www.xkcoding.com blog.xkcoding.com;
164-
165-
ssl_certificate /etc/letsencrypt/live/xkcoding.com/fullchain.pem;
166-
ssl_certificate_key /etc/letsencrypt/live/xkcoding.com/privkey.pem;
167-
168-
ssl_protocols TLSv1.2 TLSv1.3;
169-
ssl_prefer_server_ciphers off;
170-
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
171-
ssl_session_timeout 1d;
172-
ssl_session_cache shared:SSL:10m;
173-
ssl_session_tickets off;
174-
175-
root /usr/share/nginx/html;
176-
index index.html;
177-
178-
gzip on;
179-
gzip_vary on;
180-
gzip_proxied any;
181-
gzip_comp_level 6;
182-
gzip_min_length 1000;
183-
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml;
184-
185-
# ==================== 安全头(全局) ====================
186-
# HSTS - 强制 HTTPS,包含子域名
187-
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
188-
# 强制升级不安全请求
189-
add_header Content-Security-Policy "upgrade-insecure-requests" always;
190-
# 防止点击劫持
191-
add_header X-Frame-Options "SAMEORIGIN" always;
192-
# 防止 MIME 类型嗅探
193-
add_header X-Content-Type-Options "nosniff" always;
194-
# XSS 防护
195-
add_header X-XSS-Protection "1; mode=block" always;
196-
# Referrer 策略
197-
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
198-
199-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
200-
expires 1y;
201-
add_header Cache-Control "public, immutable" always;
202-
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
203-
add_header Content-Security-Policy "upgrade-insecure-requests" always;
204-
add_header X-Content-Type-Options "nosniff" always;
205-
access_log off;
206-
}
207-
208-
location ~* \.html$ {
209-
expires -1;
210-
add_header Cache-Control "no-store, no-cache, must-revalidate" always;
211-
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
212-
add_header Content-Security-Policy "upgrade-insecure-requests" always;
213-
add_header X-Frame-Options "SAMEORIGIN" always;
214-
add_header X-Content-Type-Options "nosniff" always;
215-
}
216-
217-
location / {
218-
try_files $uri $uri/ $uri.html =404;
219-
}
220-
221-
error_page 404 /404.html;
222-
}
223-
NGINX_CONF
146+
# HTTP - 重定向到 HTTPS
147+
server {
148+
listen 80;
149+
server_name xkcoding.com www.xkcoding.com blog.xkcoding.com;
150+
151+
location /.well-known/acme-challenge/ {
152+
root /usr/share/nginx/html;
153+
}
154+
155+
location / {
156+
return 301 https://$server_name$request_uri;
157+
}
158+
}
159+
160+
# HTTPS
161+
server {
162+
listen 443 ssl;
163+
server_name xkcoding.com www.xkcoding.com blog.xkcoding.com;
164+
165+
ssl_certificate /etc/letsencrypt/live/xkcoding.com/fullchain.pem;
166+
ssl_certificate_key /etc/letsencrypt/live/xkcoding.com/privkey.pem;
167+
168+
ssl_protocols TLSv1.2 TLSv1.3;
169+
ssl_prefer_server_ciphers off;
170+
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
171+
ssl_session_timeout 1d;
172+
ssl_session_cache shared:SSL:10m;
173+
ssl_session_tickets off;
174+
175+
root /usr/share/nginx/html;
176+
index index.html;
177+
178+
gzip on;
179+
gzip_vary on;
180+
gzip_proxied any;
181+
gzip_comp_level 6;
182+
gzip_min_length 1000;
183+
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml;
184+
185+
# ==================== 安全头(全局) ====================
186+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
187+
add_header Content-Security-Policy "upgrade-insecure-requests" always;
188+
add_header X-Frame-Options "SAMEORIGIN" always;
189+
add_header X-Content-Type-Options "nosniff" always;
190+
add_header X-XSS-Protection "1; mode=block" always;
191+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
192+
193+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
194+
expires 1y;
195+
add_header Cache-Control "public, immutable" always;
196+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
197+
add_header Content-Security-Policy "upgrade-insecure-requests" always;
198+
add_header X-Content-Type-Options "nosniff" always;
199+
access_log off;
200+
}
201+
202+
location ~* \.html$ {
203+
expires -1;
204+
add_header Cache-Control "no-store, no-cache, must-revalidate" always;
205+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
206+
add_header Content-Security-Policy "upgrade-insecure-requests" always;
207+
add_header X-Frame-Options "SAMEORIGIN" always;
208+
add_header X-Content-Type-Options "nosniff" always;
209+
}
210+
211+
location / {
212+
try_files $uri $uri/ $uri.html =404;
213+
}
214+
215+
error_page 404 /404.html;
216+
}
217+
NGINX_CONF
224218

225219
# 使用 SSL 配置启动 nginx
226220
docker run -d \

0 commit comments

Comments
 (0)