
我正在嘗試在 nginx 反向代理後面託管 Unifi 控制器。除了我在使用 STUN 協定時遇到問題之外,這很有效。
我在 Ubuntu 20.04 上使用 nginx 1.18。當我檢查 nginx 的載入模組時,它被列出--with-stream=dynamic
為可用,但是當我嘗試使用:listen 3478 udp;
在我的伺服器區塊中時,它失敗並顯示以下錯誤訊息:
nginx: [emerg] invalid parameter "udp" in /etc/nginx/sites-enabled/stream_unifi.example.com:7
配置stream_unifi.example.com
在上下文中載入stream
:
stream {
include /etc/nginx/sites-enabled/stream_*;
}
有什麼我遺漏的或我需要自己用一些特殊標誌編譯 nginx 嗎?
謝謝你!
完整輸出:
root@server:/etc/nginx/modules-available# nginx -V
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module
root@server:/etc/nginx/modules-available# cat ../sites-available/stream_unifi.example.com
# Unifi STUN UDP Traffic
upstream unifi_stun {
server 127.0.0.1:3478;
}
server {
listen 3478 udp;
include /etc/nginx/snippets/acmetool.conf;
location / {
proxy_pass https://unifi_stun;
proxy_responses 0;
}
}
root@server:/etc/nginx/modules-available# nginx -t
nginx: [emerg] invalid parameter "udp" in /etc/nginx/sites-enabled/stream_unifi.example.com:7
nginx: configuration file /etc/nginx/nginx.conf test failed
root@server:/etc/nginx/modules-available#
答案1
我的配置有一些問題,理查史密斯為我指出了正確的方向。
我的nginx.conf
有以下區塊:
http {
[other configuration options]
include /etc/nginx/sites-enabled/*;
}
stream {
[other configuration options]
include /etc/nginx/sites-enabled/*;
}
- 我將我的“流配置”從
/etc/nginx/sites-available/stream_unifi.example.com
符號連結到/etc/nginx/sites_enabled/stream_unifi.example.com
。這導致上圖所示的http
和stream
區塊均採用此配置nginx.conf
。解決方法是將區塊中的包含更改stream
為如下所示:
stream {
include /etc/nginx/stream-sites-enabled/*;
}
然後建立該stream-sites-enabled
目錄並符號連結/etc/nginx/sites-available/stream_unifi.example.com
到該目錄。
- 流配置本身 (
stream_unifi.example.com
) 有一些問題,必須如下所示:
upstream unifi_stun {
server 127.0.0.1:3478;
}
server {
listen 3478 udp;
proxy_pass unifi_stun;
proxy_responses 0;
}
希望這對其他人也有幫助。