Nemůžu spustit ukázkovou konfiguraci pro Nginx

HUGO

Nemůžu spustit ukázkovou konfiguraci pro Nginx
« kdy: 05. 04. 2018, 23:06:25 »
Ahoj,
tady je ukázková konfigurace pro Nginx kterou jsem použil a snažím se jí otestovat
http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html
Pokud ale restartuji nginx, dostanu chybu
Kód: [Vybrat]
Apr 05 22:56:25 proxy nginx[1363]: nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:18Poradí někdo?
« Poslední změna: 06. 04. 2018, 07:06:01 od Petr Krčmář »


ET

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #1 kdy: 06. 04. 2018, 01:28:39 »
dej sem vystup z prikazu "nginx -V" - tipuju, ze si nginx nekomiploval (This module is not built by default, it should be enabled with the --with-stream_ssl_preread_module)

Sten

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #2 kdy: 06. 04. 2018, 03:34:22 »
Ta ukázka je špatně, v dokumentaci proxy_pass se píše, že musí být v location.

HUGO

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #3 kdy: 06. 04. 2018, 03:56:19 »
dej sem vystup z prikazu "nginx -V" - tipuju, ze si nginx nekomiploval (This module is not built by default, it should be enabled with the --with-stream_ssl_preread_module)
Tady to je
Kód: [Vybrat]
nginx -V
nginx version: nginx/1.10.3
built with OpenSSL 1.1.0f  25 May 2017
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-2tpxfc/nginx-1.10.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now' --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-pcre-jit --with-ipv6 --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_geoip_module=dynamic --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 --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-auth-pam --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-echo --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/ngx_http_substitutions_filter_module

HUGO

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #4 kdy: 06. 04. 2018, 04:05:16 »
Ta ukázka je špatně, v dokumentaci proxy_pass se píše, že musí být v location.

Tak jsem to opravil, mám to teď takto

Kód: [Vybrat]
map $ssl_preread_server_name $name {
backend.example.com      backend;
default                  backend2;
}

upstream backend {
server 192.168.0.1:12345;
server 192.168.0.2:12345;
}

upstream backend2 {
server 192.168.0.3:12345;
server 192.168.0.4:12345;
}

server {
listen      12346;

location / {
proxy_pass  $name;
}

ssl_preread on;
}

Po restartu ale opět chyba :(

Kód: [Vybrat]
nginx: [emerg] unknown directive "ssl_preread" in /etc/nginx/sites-enabled/default:23


xul

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #5 kdy: 06. 04. 2018, 04:12:23 »
dej sem vystup z prikazu "nginx -V" - tipuju, ze si nginx nekomiploval (This module is not built by default, it should be enabled with the --with-stream_ssl_preread_module)
Tady to je
Kód: [Vybrat]
nginx -V
nginx version: nginx/1.10.3
built with OpenSSL 1.1.0f  25 May 2017
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-2tpxfc/nginx-1.10.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now' --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-pcre-jit --with-ipv6 --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_geoip_module=dynamic --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 --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-auth-pam --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-echo --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/ngx_http_substitutions_filter_module


Nevidim tam ten ssl_preread, precti si parametry poradne.

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #6 kdy: 06. 04. 2018, 07:34:14 »
A není chyba jenom v tomto? Zkus vložit proxy_pass do location.
Kód: [Vybrat]
...
location / {
    proxy_pass  $proxy;
}
...

Sten

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #7 kdy: 06. 04. 2018, 11:15:39 »
Tady to je
Kód: [Vybrat]
nginx -V
nginx version: nginx/1.10.3
built with OpenSSL 1.1.0f  25 May 2017
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-2tpxfc/nginx-1.10.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now' --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-pcre-jit --with-ipv6 --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_geoip_module=dynamic --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 --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-auth-pam --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-echo --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/ngx_http_substitutions_filter_module

Máte nginx 1.10.3, ngx_stream_ssl_preread je až v nginx 1.11.5

HUGO

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #8 kdy: 06. 04. 2018, 16:15:32 »
Máte nginx 1.10.3, ngx_stream_ssl_preread je až v nginx 1.11.5
Tak se mi podařilo nainstaloval novější verzi (nginx/1.13.11)

Kód: [Vybrat]
# nginx -V
nginx version: nginx/1.13.11
built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
built with OpenSSL 1.1.0f  25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.13.11/debian/debuild-base/nginx-1.13.11=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

nic méně restart stále neprojde :(
Kód: [Vybrat]
nginx: [emerg] "ssl_preread" directive is not allowed here in /etc/nginx/conf.d/default.conf:23
Jak to povolit jsem za 2 hodiny na webu fakt nenašel...

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #9 kdy: 06. 04. 2018, 18:17:10 »
Musíš to mít mimo http block v samostatném bloku stream.

Kód: [Vybrat]
http {
...
}

stream {
map $ssl_preread_server_name $name {
    backend.example.com      backend;
    default                  backend2;
}

upstream backend {
    server 192.168.0.1:12345;
    server 192.168.0.2:12345;
}

upstream backend2 {
    server 192.168.0.3:12345;
    server 192.168.0.4:12345;
}

server {
    listen      12346;
    proxy_pass  $name;
    ssl_preread on;
}
}

HUGO

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #10 kdy: 06. 04. 2018, 18:28:34 »
Musíš to mít mimo http block v samostatném bloku stream.
Když to dám jak jsi napsal, tak dostanu zase jinou chybu :(
Kód: [Vybrat]
nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/conf.d/default.conf:1

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #11 kdy: 07. 04. 2018, 20:20:18 »
Já si zkompiloval Nginx s tím, co je potřeba (viz. třeba https://www.vultr.com/docs/how-to-compile-nginx-from-source-on-ubuntu-16-04), ukázkovou konfiguraci vložil na konec nginx.conf do bloku stream a vše jelo bez problémů.

Re:Nemůžu spustit ukázkovou konfiguraci pro Nginx
« Odpověď #12 kdy: 07. 04. 2018, 21:21:52 »
nginx má na webu dokumentaci. U každé direktivy je zdokumentováno, ve které části konfigurace se dá použít. Je zbytečné zkoušet to metodou pokusu a omylu.