流中的NGINX location指令
我在我的一台服务器上安装了Nginx,以便用作我的应用程序的负载平衡器。 我的配置基于此处找到的配置: 所以我的配置是:流中的NGINX location指令,nginx,Nginx,我在我的一台服务器上安装了Nginx,以便用作我的应用程序的负载平衡器。 我的配置基于此处找到的配置: 所以我的配置是: load_module /usr/lib/nginx/modules/ngx_stream_module.so; worker_processes 4; worker_rlimit_nofile 40000; events { worker_connections 8192; } stream { upstream rancher_servers_htt
load_module /usr/lib/nginx/modules/ngx_stream_module.so;
worker_processes 4;
worker_rlimit_nofile 40000;
events {
worker_connections 8192;
}
stream {
upstream rancher_servers_http {
least_conn;
server <ipnode1>:80 max_fails=3 fail_timeout=5s;
server <ipnode2>:80 max_fails=3 fail_timeout=5s;
server <ipnode3>:80 max_fails=3 fail_timeout=5s;
}
server {
listen 80;
proxy_pass rancher_servers_http;
}
upstream rancher_servers_https {
least_conn;
server <ipnode1>:443 max_fails=3 fail_timeout=5s;
server <ipnode2>:443 max_fails=3 fail_timeout=5s;
server <ipnode3>:443 max_fails=3 fail_timeout=5s;
}
server {
listen 443;
proxy_pass rancher_servers_https;
}
}
但它告诉我
在/etc/nginx/nginx.conf:21中不允许使用“location”指令
假设流配置中不允许使用location指令,我尝试添加如下http块:
...
stream {
...
}
http {
server {
listen 443;
location /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
}
server {
listen 80;
location /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
}
}
但后来我得到了这个信息:
将()绑定到0.0.0.0:443失败(98:地址已在使用)
(端口80也是如此)
有人能帮我吗?如何在不影响实际配置的情况下添加location指令
谢谢你的阅读
编辑
看来stream
指令阻止了我添加其他标准指令。我试图在服务器
中添加客户端_max_body_size
,但我遇到了同样的问题:
此处不允许使用指令
现在,您的安装程序使用nginx作为TCP代理。nginx的这种配置在不进行分析的情况下通过流量——它可以是ssh、rdp或任何流量,并且无论协议如何,它都可以工作,因为nginx不尝试检查流内容 这就是location指令在流上下文中不起作用的原因——它是与http协议相关的函数 要利用高级协议分析,nginx需要了解协议的运行情况,即配置为HTTP反向代理 为了让it工作,服务器指令应该放在http范围而不是流范围中
http {
server {
listen 0.0.0.0:443 ssl;
include /etc/nginx/snippets/letsencrypt.conf;
root /var/www/html;
server_name XXXX;
location / {
proxy_pass http://rancher_servers_http;
}
location /.well-known/carddav {
proxy_pass http://$host:$server_port/remote.php/dav;
}
location /.well-known/caldav {
proxy_pass http://$host:$server_port/remote.php/dav;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /var/www/letsencrypt;
}
root /var/www/html;
server_name xxxx;
location / {
proxy_pass http://rancher_servers_http;
}
}
}
这种方法的缺点是需要重新配置证书管理。
但您将把ssl加密加载到nginx,并获得基于http查询的智能平衡
http {
server {
listen 0.0.0.0:443 ssl;
include /etc/nginx/snippets/letsencrypt.conf;
root /var/www/html;
server_name XXXX;
location / {
proxy_pass http://rancher_servers_http;
}
location /.well-known/carddav {
proxy_pass http://$host:$server_port/remote.php/dav;
}
location /.well-known/caldav {
proxy_pass http://$host:$server_port/remote.php/dav;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /var/www/letsencrypt;
}
root /var/www/html;
server_name xxxx;
location / {
proxy_pass http://rancher_servers_http;
}
}
}