Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is nginx complaining of an unknown directive?

Tags:

nginx

I'm trying to direct all HTTP requests resembling /<uuid4> to a specific HTTP server running on the localhost. Below is the relevant location line in my 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;
    }
}

When starting nginx, I get the following error: nginx: [emerg] unknown directive "8}-([0-9a-f]" in /etc/nginx/sites-enabled/nginx.conf:30

What gives?

like image 242
Louis Thibault Avatar asked Sep 26 '22 18:09

Louis Thibault


1 Answers

Actually you have another error. I've checked your server block and got following:

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

This is error about missing protocol in proxy_pass localhost:8000; line. After fixing it to proxy_pass http://localhost:8000; configs test passed.

Probably you're looking into old (or wrong) error log.

like image 128
Alexey Ten Avatar answered Sep 29 '22 23:09

Alexey Ten