feat: SEO + Nginx optimization
Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 21s

- Update sitemap.xml to include /v1/health endpoint
- Add proper 404 handling (JSON for API paths, HTML for browser paths)
- Create optimized nginx config with gzip, cache headers, specific locations
- Add logrotate configuration for DocFast logs
- Add security headers and static asset caching
This commit is contained in:
openclawd 2026-02-16 08:30:14 +00:00
parent 9541ae1826
commit 210e71e3d8
4 changed files with 152 additions and 0 deletions

13
logrotate-docfast Normal file
View file

@ -0,0 +1,13 @@
/var/log/docfast*.log {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
# Send USR1 signal to dockerized apps to reopen log files
/bin/kill -USR1 $(cat /var/run/docker.pid 2>/dev/null) 2>/dev/null || true
endscript
}

90
nginx-docfast.conf Normal file
View file

@ -0,0 +1,90 @@
server {
server_name docfast.dev www.docfast.dev;
client_max_body_size 10m;
# Enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/html
text/css
application/json
application/javascript
text/xml
application/xml
application/xml+rss
text/javascript;
# Specific locations for robots.txt and sitemap.xml with caching
location = /robots.txt {
proxy_pass http://127.0.0.1:3100;
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_set_header X-Forwarded-Proto $scheme;
# Cache for 1 day
expires 1d;
add_header Cache-Control "public, max-age=86400";
add_header X-Content-Type-Options nosniff;
}
location = /sitemap.xml {
proxy_pass http://127.0.0.1:3100;
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_set_header X-Forwarded-Proto $scheme;
# Cache for 1 day
expires 1d;
add_header Cache-Control "public, max-age=86400";
add_header X-Content-Type-Options nosniff;
}
# Static assets caching
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://127.0.0.1:3100;
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_set_header X-Forwarded-Proto $scheme;
# Cache static assets for 1 week
expires 7d;
add_header Cache-Control "public, max-age=604800, immutable";
add_header X-Content-Type-Options nosniff;
}
# All other requests
location / {
proxy_pass http://127.0.0.1:3100;
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_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 60s;
# Security headers
add_header X-Content-Type-Options nosniff;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/docfast.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/docfast.dev/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = docfast.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name docfast.dev www.docfast.dev;
return 404; # managed by Certbot
}

View file

@ -2,4 +2,5 @@
<urlset xmlns="http://www.sitemapns.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemapns.org/schemas/sitemap/0.9">
<url><loc>https://docfast.dev/</loc><changefreq>weekly</changefreq><priority>1.0</priority></url> <url><loc>https://docfast.dev/</loc><changefreq>weekly</changefreq><priority>1.0</priority></url>
<url><loc>https://docfast.dev/docs</loc><changefreq>weekly</changefreq><priority>0.8</priority></url> <url><loc>https://docfast.dev/docs</loc><changefreq>weekly</changefreq><priority>0.8</priority></url>
<url><loc>https://docfast.dev/v1/health</loc><changefreq>daily</changefreq><priority>0.3</priority></url>
</urlset> </urlset>

View file

@ -183,6 +183,54 @@ app.get("/api", (_req, res) => {
}); });
}); });
// 404 handler - must be after all routes
app.use((req, res) => {
// Check if it's an API request
const isApiRequest = req.path.startsWith('/v1/') || req.path.startsWith('/api') || req.path.startsWith('/health');
if (isApiRequest) {
// JSON 404 for API paths
res.status(404).json({
error: "Not Found",
message: `The requested endpoint ${req.method} ${req.path} does not exist`,
statusCode: 404,
timestamp: new Date().toISOString()
});
} else {
// HTML 404 for browser paths
res.status(404).send(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 - Page Not Found | DocFast</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚡</text></svg>">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: #0b0d11; color: #e4e7ed; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.container { background: #151922; border: 1px solid #1e2433; border-radius: 16px; padding: 48px; max-width: 520px; width: 100%; text-align: center; }
h1 { font-size: 3rem; margin-bottom: 12px; font-weight: 700; color: #34d399; }
h2 { font-size: 1.5rem; margin-bottom: 16px; font-weight: 600; }
p { color: #7a8194; margin-bottom: 24px; line-height: 1.6; }
a { color: #34d399; text-decoration: none; font-weight: 600; }
a:hover { color: #5eead4; }
.emoji { font-size: 4rem; margin-bottom: 24px; }
</style>
</head>
<body>
<div class="container">
<div class="emoji"></div>
<h1>404</h1>
<h2>Page Not Found</h2>
<p>The page you're looking for doesn't exist or has been moved.</p>
<p><a href="/"> Back to DocFast</a> | <a href="/docs">Read the docs</a></p>
</div>
</body>
</html>`);
}
});
async function start() { async function start() {
// Initialize PostgreSQL // Initialize PostgreSQL
await initDatabase(); await initDatabase();