A
A
Arsen Abakarov2016-09-06 19:01:28
Nginx
Arsen Abakarov, 2016-09-06 19:01:28

Nginx, add to .html url?

The task seems to be simple, but I didn’t work much with nginx, I read the docks, forums, and threw in such a config

server {
    listen      80;
    server_name 10.10.8.1;
    charset     utf-8;

    client_max_body_size 75M;

    location /media  {
        alias /web/media;
    }

    location /static {
        alias /web/static;
    }

    location /robots.txt {
        alias /web/robots.txt;
    }

    location /presentations {
        alias /web/landings;
        try_files $uri @present;
    }

    location @present {
        rewrite ^/presentations/(.*)$ /presentations/$1.html break;
    }

    location / {
        uwsgi_pass  unix:/websocket/mysite.sock;
        include     /etc/nginx/uwsgi_params;
    }
}

The site does not return the page by the url /presentations/idn, this is what is in the logs:
10.10.8.6 - - [06/Sep/2016:18:54:20 +0300] "GET /presentations/idn HTTP/1.1" 404 169 "- " "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0" "-"
2016/09/06 18:54:20 [error] 6#6: *4 open() " /etc/nginx/html/presentations/idn.html" failed (2: No such file or directory), client: 10.10.8.6, server: 10.10.8.1, request: "GET /presentations/idn HTTP/1.1", host : "10.10.8.1"
In my heart I don't understand where the alias is lost? Why is there "/etc/nginx/html/presentations/idn.html" I have already looked at the config a hundred times, perhaps from the side the error will be immediately visible

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2016-09-06
@ArsenAbakarov

The nginx config is declarative. alias remains in location /presentations/, and the request is already processed in location @present
However, in fact, the config needs to be made simpler:

server {
    listen      80;
    server_name 10.10.8.1;
    charset     utf-8;

    client_max_body_size 75M;

    root /web;

    location /media  {
    }

    location /static {
    }

    location /robots.txt {
    }

    location /presentations {
        alias /web/landings;
        try_files $uri $uri.html =404;
    }

    location / {
        uwsgi_pass  unix:/websocket/mysite.sock;
        include     /etc/nginx/uwsgi_params;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question