skip to Main Content

My Nginx configuration files, the same contect with different version, the other one is nginx/1.10.3 takes effect , but current version nginx/1.16.1 error occur, detail as below:

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

I checked the official document, still did not found where I’m wrong.

Could you help me to find where not correct.

2

Answers


  1. proxy_pass is allowed in a location context

    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;
        }
    }
    
    Login or Signup to reply.
  2. You have been done correctly except one error. http{} includes the inheritance of all *.conf including *.stream.conf. You need to endure *.stream.conf files into a separate conf.stream.d folder and perform inheritance in stream from the correct folder.

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search