nginx - 您如何正确观看和重新加载 Nginx conf?

标签 nginx

我有两个问题:

  • 有没有区别:nginx -s reloadpkill -HUP -F nginx.pid
  • 查看 Nginx conf 文件并在更改时测试 conf 文件 (nginx -t) 的最简单方法是什么,如果它通过重新加载 Nginx。这可以通过 runit 或像 Supervisor 这样的流程管理器来完成吗?

最佳答案

#!/bin/bash

# NGINX WATCH DAEMON
#
# Author: Devonte
#
# Place file in root of nginx folder: /etc/nginx
# This will test your nginx config on any change and
# if there are no problems it will reload your configuration
# USAGE: sh nginx-watch.sh

# Set NGINX directory
# tar command already has the leading /
dir='etc/nginx'

# Get initial checksum values
checksum_initial=$(tar --strip-components=2 -C / -cf - $dir | md5sum | awk '{print $1}')
checksum_now=$checksum_initial

# Start nginx
nginx

# Daemon that checks the md5 sum of the directory
# ff the sums are different ( a file changed / added / deleted)
# the nginx configuration is tested and reloaded on success
while true
do
    checksum_now=$(tar --strip-components=2 -C / -cf - $dir | md5sum | awk '{print $1}')

    if [ $checksum_initial != $checksum_now ]; then
        echo '[ NGINX ] A configuration file changed. Reloading...'
        nginx -t && nginx -s reload;
    fi

    checksum_initial=$checksum_now

    sleep 2
done

关于nginx - 您如何正确观看和重新加载 Nginx conf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16817077/

相关文章:

docker - 将 SSL 证书添加到 NGINX docker 容器

apache - Brew 安装 Httpd : Welcome to Nginx?

ssl - HTTPS 重定向不适用于 nginx-ingress-controller 的默认后端

docker - Docker上的UCP和HTTP服务器共存

NGINX 透明 TCP 代理

ssl - nginx多一个ssl配置

node.js - 从 nginx proxy_pass 中删除路径的开头

node.js - Nginx 反向代理 : How to get access to different container via subdomains?

http - 如果不是全部大写,Nginx 将拒绝自定义 HTTP 方法

python - 使用 nginx/gunicorn 上传 Django 文件 - 媒体权限