目前,我的团队继承的一个项目在 10 多个环境中的 nginx 配置完全困惑,我们想实现版本控制策略,但我不确定人们“通常”如何实现这一目标。您将整个 nginx conf 文件夹设为一个 git repo 并忽略您不想要的版本?或者有一个包含配置文件 repo 的单独文件夹并使用脚本部署文件?
最佳答案
我们通过单独的 Git 存储库管理它,专用于 nginx 配置。是的,它包括 /etc/nginx/
目录中的所有内容。
但它没有直接在服务器上同步,而是使用 bash 脚本来 pull 更改、更新配置和重新加载 nginx 配置。
脚本示例:
# Pull changes
git pull
# Sync changes excluding .git directory
rsync -qauh ./* "/etc/nginx" --exclude=".git"
# Set proper permissions
chmod -R 644 /etc/nginx
find /etc/nginx -type d -exec chmod 700 {} \;
# If you store SSL certs under `/etc/nginx/ssl`
# Set proper permission for SSL certs
chmod -R 600 /etc/nginx/ssl
chmod -R 400 /etc/nginx/ssl/*
# Reload nginx config
# but only if configtest is passed
nginx -t && service nginx reload
关于linux - Nginx 配置版本控制策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44159978/