nginx - 为什么 nginx 提示未知指令?

标签 nginx

我正在尝试引导所有类似于 /<uuid4> 的 HTTP 请求到在 localhost 上运行的特定 HTTP 服务器。以下是相关的location我的 nginx.conf 中的行:

# 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
是什么赋予了?

最佳答案

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

$ 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; 中缺少协议(protocol)的错误线。将其修复为 proxy_pass http://localhost:8000; 后配置测试通过。

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

关于nginx - 为什么 nginx 提示未知指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589283/

相关文章:

ubuntu - Nginx 重定向 https ://www to https://

linux - Fail2Ban 在 10 分钟后解禁。 bantime 没有警告?

nginx 位置索引指令不起作用

node.js - 使用docker-compose时如何为mongodb图像添加--auth?

nginx - 具有Nginx的Elasticsearch Client与不具有Nginx的Elasticsearch Client

nginx - Puma 配方在 CentOS 上失败

nginx - 如何设置 NGINX 以根据位置(在相同的 server_name 下)和子路由部署不同的单页应用程序(SPA 的...即静态文件)

c# - Nginx 作为 Ubuntu 上带有 UseRewriter 的 Asp.Net Core 2.0 Web 应用程序的反向代理

linux - nginx: [emerg] 未知指令 ""在/etc/nginx/sites-enabled/example.com:3

node.js - 对于 Node/Mongo/NginX,哪种缓存方法最快/最轻?