【发布时间】:2019-05-17 10:43:41
【问题描述】:
我的 nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream app_servers {
server 127.0.0.1:5000;
server 127.0.0.1:5001;
}
server {
listen 6200;
server_name test;
add_header X-GG-Cache-Status $upstream_cache_status;
include rewrite.conf;
}
}
和我的 rewrite.conf 在同一个文件夹中
location = / {
rewrite ^/some-custom-destination/?$ /destination/detail?id=33;
proxy_pass http: //app_servers;
proxy_intercept_errors on;
error_page 400 404 /;
error_page 500 502 503 504 /error.html;
location = /error.html {
root /etc/nginx/;
}
}
当我使用 nginx -s reload 命令时出现该错误:nginx: [emerg] unknown directive "location" in /etc/nginx/rewrite.conf:1
我该如何解决这个问题?
请帮忙。谢谢。
【问题讨论】:
-
我不知道你是如何得到这个特定错误的。当我测试您的配置时,
proxy_pass由于虚假空间而失败,第二个location失败,因为它嵌套在完全匹配的location块中。 -
由于复制粘贴,空格无关紧要。我只是想像这样将我的配置拆分为位置。如何拆分我的配置?
-
请在重新加载(或尝试)之前使用 nginx -t...
-
您不能嵌套在 = location 块中。它甚至在数学上是正确的,因为 1=1 检查但 1=3 并没有完全注册。将您的“完全匹配”请求分开,并让您的 = / just / 如果它不需要绝对是 domain.com - location / 也将匹配 domain.com/blah/ 下的任何内容(如果未在其他地方指定)
标签: nginx configuration config