2

I am trying to redirect in nginx with the stock code:

    server {
       listen 80;
       server_name www.example.com;
       return 301 $scheme://example.com$request_uri;
    }

But get this error:

nginx unknown directive "return"

Nginx is very recent, installed on ubuntu using apt install rather than compiled from source.

nginx version: nginx/1.19.0
built by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2) 
built with OpenSSL 1.1.0h  27 Mar 2018
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -m64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -march=native -mtune=native -fasynchronous-unwind-tables' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --error-log-path=/var/log/nginx/nginx_error --http-log-path=/var/log/nginx/nginx_log --user=nginx --group=nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --with-http_ssl_module --with-file-aio --with-openssl=/src/openssl --with-poll_module --with-http_stub_status_module --with-http_v2_module --with-threads --with-zlib=/src/zlib-1.2.11 --with-http_gzip_static_module --without-http_autoindex_module --without-http_browser_module --without-http_geo_module --without-http_memcached_module --without-http_ssi_module --without-http_userid_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_split_clients_module --without-http_uwsgi_module --without-http_scgi_module --without-http_limit_conn_module --without-http_rewrite_module --http-client-body-temp-path=/dev/shm/client_temp --http-proxy-temp-path=/dev/shm/proxy_temp --http-fastcgi-temp-path=/dev/shm/fastcgi_temp --http-uwsgi-temp-path=/dev/shm/uwsgi_temp --http-scgi-temp-path=/dev/shm/scgi_temp --add-module=/src/headers-more```

richp10
  • 820
  • 8
  • 20

1 Answers1

5

Directive return contains in ngx_http_rewrite_module. According your configure option --without-http_rewrite_module nginx you're running compiled without needed module.

Try to reinstall nginx from official repos or install needed module.

Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55