nginx リバース プロキシ UDP トラフィック (無効なパラメータ "udp")

nginx リバース プロキシ UDP トラフィック (無効なパラメータ "udp")

私は、nginx リバース プロキシの背後に Unifi コントローラーをホストしようとしています。STUN プロトコルに問題があることを除けば、これはうまく機能します。

Ubuntu 20.04 で nginx 1.18 を使用しています。nginx のロードされたモジュールを確認すると、--with-stream=dynamic使用可能としてリストされますが、サーバー ブロックで use: を実行しようとすると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

私の設定にはいくつか問題がありましたが、RichardSmith が正しい方向を示してくれました。

私のnginx.confブロックは次の通りです:

http {
        [other configuration options]
        include /etc/nginx/sites-enabled/*;
}

stream {
        [other configuration options]
        include /etc/nginx/sites-enabled/*;
}
  1. 「ストリーム設定」を から にシンボリックリンクしました/etc/nginx/sites-available/stream_unifi.example.com。これにより、この設定が、上記の のとブロックの/etc/nginx/sites_enabled/stream_unifi.example.com両方で取得されるようになりました。修正するには、ブロック内の include を次のように変更します。httpstreamnginx.confstream
stream {
        include /etc/nginx/stream-sites-enabled/*;
}

次に、このstream-sites-enabledディレクトリを作成し、/etc/nginx/sites-available/stream_unifi.example.comそのディレクトリへのシンボリックリンクを作成します。

  1. ストリーム構成自体 ( stream_unifi.example.com) にはいくつか問題があり、次のようになります。
upstream unifi_stun {
        server 127.0.0.1:3478;
}

server {
    listen 3478 udp;
    proxy_pass unifi_stun;
    proxy_responses 0;
}

それが他の誰かにとっても役立つことを願っています。

関連情報