为什么 nginx 抱怨未知指令?

Why is nginx complaining of an unknown directive?

我正在尝试将所有类似于 /<uuid4> 的 HTTP 请求定向到本地主机上的特定 HTTP 服务器 运行。下面是我的 nginx.conf:

中的相关 location
# nginx.conf
upstream django {
    server unix:///app/django.sock; # for a file socket
}

server {
    access_log /var/log/access.log;
    error_log /var/log/error.log;
    listen      80;

    server_name 127.0.0.1;
    charset     utf-8;

    client_max_body_size 75M;

    # Django media
    location /media  {
        alias /app/media;
    }

    location /static {
        alias /app/static;
    }

    location ~* "[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$" {  # matches UUIDv4
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass localhost:8000;
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /app/conf/uwsgi_params;
    }
}

启动 nginx 时,出现以下错误:nginx: [emerg] unknown directive "8}-([0-9a-f]" in /etc/nginx/sites-enabled/nginx.conf:30

什么给了?

其实你还有一个错误。我检查了您的服务器块并得到以下信息:

$ sudo nginx -t
nginx: [emerg] invalid URL prefix in /etc/nginx/sites-enabled/test:23
nginx: configuration file /etc/nginx/nginx.conf test failed

这是关于 proxy_pass localhost:8000; 行中缺少协议的错误。将其修复为 proxy_pass http://localhost:8000; 配置测试通过后。

您可能正在查看旧的(或错误的)错误日志。