Nginx
1 前言
一个问题,一篇文章,一出故事。
最近由于需要发布维护公告,想着这种东西以后用得着,于是总结本章。
2 最佳实践
2.1 创建维护页面
vim /var/www/nextcloud.cmdschool.org/maintenance.html
创建如下代码,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Maintenance Notice - Nextcloud</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 50px; } h1 { color: #333; } p { color: #666; } </style> </head> <body> <h1 id="maintenance-title"></h1> <p id="maintenance-message"></p> <script> var lang = navigator.language || navigator.userLanguage; var title, message; if (lang.startsWith('zh')) { title = '维护通知'; message = '我们正在进行系统维护,暂时无法访问 Nextcloud。请稍后再试。感谢您的理解和耐心。'; } else { title = 'Maintenance Notice'; message = 'We are currently undergoing system maintenance and Nextcloud is temporarily unavailable. Please try again later. Thank you for your understanding and patience.'; } document.getElementById('maintenance-title').textContent = title; document.getElementById('maintenance-message').textContent = message; </script> </body> </html>
2.2 设置Nginx访问维护页面
vim /etc/nginx/conf.d/nextcloud.cmdschool.org_443_nextcloud.conf
创建如下代码,
server { location / { return 503; #... } error_page 503 @maintenance; location @maintenance { root /var/www/nextcloud.cmdschool.org; rewrite ^(.*)$ /maintenance.html break; } location = /maintenance.html { root /var/www/nextcloud.cmdschool.org; } }
设置后,你需要重载服务使配置生效
nginx -t systemctl reload nginx
没有评论