nginx - nginx 未知指令“return”
问题描述
我正在尝试使用股票代码在 nginx 中重定向:
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
但是得到这个错误:
nginx unknown directive "return"
Nginx 是最新的,使用 apt install 安装在 ubuntu 上,而不是从源代码编译。
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```
解决方案
指令return
包含在ngx_http_rewrite_module中。根据您的配置选项--without-http_rewrite_module
nginx,您正在运行编译而无需模块。
推荐阅读
- c# - 为什么字符串方法(对象对象)可能与 Func 不匹配
- c - 是否在 NaCL 库中替换了 Curve25519?
- python-3.x - 输出未在外部文本文件中打印
- node.js - 如何使用 find() 函数从 MongoDB 调用数据?
- sql - 无法基于 JOINS 执行连接两个表
- c - 如何在输入长度未知的情况下读取以逗号分隔的数字?
- java - 当我按下返回导航按钮时活动重新启动
- git - git file getting deleted again and again
- reactjs - TS2508 (TS) 尝试扩展 React 组件类时,没有基本构造函数具有指定数量的类型参数
- php - DateTimeImmutable 今年的第一天