微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Can“include”指令是否可以在nginx的上游模块中使用?

我的网站使用两个应用服务器,即app1和app2,所以在configuration中我有这样的东西:

upstream cluster { server app1:8080; server app2:8080; }

由于每次我更新代码,我需要重新启动两个服务器进程,我希望服务不受干扰,我将手动执行这些步骤:

在上游模块中注释app1 ,以便将其修改为:

upstream cluster { #server app1:8080; server app2:8080; }

运行Nginx -s reload

如何防止用户访问包含文件

g ++认头包含列表

使用MAX_ORDER /包含mmzone.h

如何通过.htaccess设置PHP包含path?

致命错误C1083:无法打开包含文件:'iostream':没有这样的文件或目录

在app1更新代码并重新启动服务器程序,然后在上游块中取消对app1注释

做app2步骤1-3

我想写一个脚本来省去这个单调乏味的工作,所以我希望这样做:

一个名为“available”的文件夹,其中包含表单as中的app1.conf和app2.conf

server app1:8080;

让另一个名为“enabled”的文件夹包含app1.conf和app2.conf的软链接

将上游群集修改

upstream cluster { include /usr/local/Nginx/conf/enabled/*; }

所以每次我需要禁用任何应用程序服务器时,我可以从“启用”文件夹中删除相应的软链接,稍后可以通过运行ln -s来恢复它

然而,这种方法不能正常工作,因为我收到了来自Nginx错误信息:

[emerg]:“include”指令在这里是不允许的。

这是否include不能被放入上游区块? 我想我并不孤单,在这种情况下,禁用和启用服务器时,其他人通常如何处理它?

C Linux的错误 – conio.h:没有这样的文件或目录

Windows XPpath问题

如何使Apache服务于index.PHP而不是index.html?

全球包括在VS2013上的Windows上的path

如何限制PHP应用程序到他们自己的目录和他们自己的PHP.ini?

不幸的是,Nginx无法处理上游的include指令。 但是你可以使用这个脚本来管理你的上游服务器:

Nginx.conf的http部分的某处:

include /usr/local/Nginx/conf/upstream.conf

创建空文件

touch /usr/local/Nginx/conf/upstream.conf

使用此脚本来管理上游服务器( upstreamctl.sh ):

#!/bin/bash if [ -n "$1" -a -n "$2" ]; then action="$1"; target="$2"; else echo "Usage: $0 (add|rm) server:port" exit 0; fi; # Path to Nginx binary BIN="/usr/local/Nginx/sbin/Nginx" # Path to upstream config file CONF="/usr/local/Nginx/conf/upstream.conf" SERVERS=`cat $CONF | grep server` output="upstream cluster {" if [ $action == "add" ]; then echo -e "$output" > $CONF if $( echo $SERVERS | grep --quiet $target ); then echo "Warning: server is already enabled." else SERVERS="$SERVERSntserver $target;" fi echo -e "$SERVERS" >> $CONF echo "}" >> $CONF elif [ $action == "rm" ]; then sed -i "/$target/d" $CONF else echo "UnkNown action" fi # Check changes: $BIN -t

在你的情况下,你可以运行:

./upstreamctl.sh add app1:8080

./upstreamctl.sh rm app2:8080

只要把这个放在这里,以防我们可以帮助别人:

Include指令可以用在Nginx的更高版本的上游模块中。

例:

/etc/Nginx/upstream.conf

server ip:port; server ip:port;

/etc/Nginx/conf.d/default.conf

upstream cluster { include /etc/Nginx/upstream.conf; } server { listen 80; server_name localhost; location / { proxy_pass http://cluster; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/Nginx/html; } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐