Nginx 配置版本控制策略

Nginx Configuration Versioning Strategy

目前我的团队继承的一个项目在 10 多个环境中的 nginx 配置完全混乱,我们想实施版本控制策略,但我不确定人们 "normally" 如何实现这一点。您将整个 nginx conf 文件夹设为 git 存储库并忽略您不想要的版本?或者有一个包含配置文件 repo 的单独文件夹并使用脚本部署文件?

我们通过单独的 Git 存储库管理它,专用于 nginx 配置。是的,它包括 /etc/nginx/ 目录中的所有内容。

但它没有直接在服务器上同步,而是使用 bash 脚本来拉取更改、更新配置和重新加载 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