我已经了解到,您可以testing一个configuration,而无需通过以下部署:
sudo nginx -t -c /home/ubuntu/test/example.conf
但是如果我在一个不可写的文件系统上呢? 有没有什么办法nginx可以在configuration中通过命令行上的string? 或者,有没有其他的程序或帮手脚本可以做到这一点?
如果你没有可写的根目录,你应该使用类似tmpfs的/ tmp可写。 很多* nix userland软件都希望/ tmp是可写的。
$ tf=$(mktemp) $ sed -e "s/#customer_ip#/$ip/g" /etc/nginx/nginx-template.conf >$tf $ nginx -t -c $tf nginx: the configuration file /tmp/tmp.lZ6HpnxWqE syntax is okay
有些炮弹有这样的速记:
$ zsh -c 'nginx -t -c =(sed -e "s/#customer_ip#/$ip/g" /etc/nginx/nginx-template.conf)'
相对include引用其他nginxconfiguration片段的path,如include fastcgi.conf; 在你的(临时或过程replace)configuration文件将无法正常工作。 你将不得不用绝对pathreplace它们,例如: include /etc/nginx/fastcgi.conf;