Opened 2 years ago

Closed 2 years ago

#1481 closed enhancement (wontfix)

nginx -t should throw error when merge_slashes is used in non-default server block

Reported by: https://stackoverflow.com/users/1171032/macroman Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.12.x
Keywords: Cc:
uname -a: Linux test-dev 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.12.2
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
built with OpenSSL 1.0.2g 1 Mar 2016
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 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

Description

According to the documentation (http://nginx.org/en/docs/http/ngx_http_core_module.html#merge_slashes), using merge_slashes in a server block, will only work when that block is the default.

As it is not possible for merge_slashes to have an effect within a non-default server block, nginx -t should throw an error if used in one.

Something similar to using it in a location block may work well: nginx: [emerg] "merge_slashes" directive is not allowed here in /etc/nginx/nginx.conf:36

Included is a minimal config with a non-functional merge_slashes directive on line 36 but passes nginx -t

Attachments (1)

nginx.conf (768 bytes ) - added by https://stackoverflow.com/users/1171032/macroman 2 years ago.
Minimal config demonstrating invalid use of merge_slashes

Download all attachments as: .zip

Change History (2)

by https://stackoverflow.com/users/1171032/macroman, 2 years ago

Attachment: nginx.conf added

Minimal config demonstrating invalid use of merge_slashes

comment:1 by Maxim Dounin, 2 years ago

Resolution: wontfix
Status: newclosed

While it might be helpful, it certainly wouldn't be trivial to automatically find out where merge_slashes make sense, and where it is not. For example, consider the following configuration:

server {
    listen 80;
}

server {
    listen 80;
    listen 81;
    server_name example.com;
    merge_slashes off;
}

In this example, merge_slashes off; is certainly valid, though it won't work for requests on the port 80. Moreover, things are even more complicated in case of SSL - a server block might be selected at SNI level, and merge_slashes will work, or it might be selected at HTTP level based on the Host header, and it will be too late to change merge_slashes.

Moreover, the following configuration does not use merge_slashes in non-default server{} blocks at all, yet it is equally confusing:

merge_slashes off;

server {
    listen 80;
    merge_slashes on;
}

server {
    listen 80;
    server_name example.com;
}

Overall, I don't think that trying to improve things here worth the effort.

Note: See TracTickets for help on using tickets.