nginx: [emerg] "proxy_pass" 指令在 /etc/nginx/conf.d/rmq.stream.conf:8 中不允许

nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/conf.d/rmq.stream.conf:8

我的Nginx配置文件,不同版本相同,另外一个是nginx/1.10.3生效,但是当前版本nginx/1.16.1出现错误,详情如下:

anom@d2-oradb01:/etc/nginx/conf.d$ sudo nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1c FIPS  28 May 2019 (running with OpenSSL 1.1.1g FIPS  21 Apr 2020)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
anom@d2-oradb01:/etc/nginx/conf.d$ sudo lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 7.2 (Maipo)
Release:    7.2
Codename:   Maipo
anom@d2-oradb01:/etc/nginx/conf.d$ cat ../nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;
}

stream {
    include /etc/nginx/conf.d/*.stream.conf;
}
anom@d2-oradb01:/etc/nginx/conf.d$ cat rmq.stream.conf 
upstream devrmq {
    server 10.32.84.74:5672 weight=5;
    server 10.32.84.75:5672;
}

server {
    listen 192.168.1.99:25672;
    proxy_pass devrmq;
    # proxy_ssl_certificate     /etc/ssl/certs/rabbit-client.cert.pem;
    # proxy_ssl_certificate_key /etc/ssl/certs/rabbit-client.key.pem;
}
anom@d2-oradb01:/etc/nginx/conf.d$ sudo nginx -t
nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/conf.d/rmq.stream.conf:8
nginx: configuration file /etc/nginx/nginx.conf test failed

我查了官方文档,还是没发现哪里错了。

能帮我看看哪里不对吗

proxy_pass 允许出现在位置上下文中

server {
    listen 192.168.1.99:25672;
    
    # proxy_ssl_certificate     /etc/ssl/certs/rabbit-client.cert.pem;
    # proxy_ssl_certificate_key /etc/ssl/certs/rabbit-client.key.pem;
    location / {
       proxy_pass http://devrmq;
    }
}

除一处错误外,您已正确完成。 http{} 包括所有 *.conf 包括 *.stream.conf 的继承。您需要将 *.stream.conf 文件保存到单独的 conf.stream.d 文件夹中,并从正确的文件夹中在流中执行继承。

anom@d2-oradb01:/etc/nginx/conf.d$ cat ../nginx.conf:
http {    ...
    include /etc/nginx/conf.d/*.conf;
}

stream {
    include /etc/nginx/conf.stream.d/*.conf;
}

anom@d2-oradb01:/etc/nginx/conf.stream.d$ cat rmq.stream.conf: 

server {
    listen 192.168.1.99:25672;
    proxy_pass 10.32.84.75:5672;
}

Euler circles for include