A
A
Artyom2019-04-19 10:44:19
Nginx
Artyom, 2019-04-19 10:44:19

How to allow one address over http in nginx?

There is an nginx config that contains paths for static files, etc.
Also, there are settings for redirecting to https and from www to non-www. Yandex, when indexing a site, for some reason cannot find favicon.ico, although it is available at the address and is written in the page code. It seems to me that the matter is in https, because the robot wants to open the page via http and instead of "200 OK" it receives "301 Moved permanently". Is it possible to register http for a single address?
UPD. It's also possible that I remove the trailing slash, but 200 OK arrives, so this is probably unlikely.

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.example.ru;
    return 301 https://example.ru$request_uri;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.ru/privkey.pem;
}

server {
  listen 80;
  listen [::]:80;
  server_name example.ru www.example.ru;
  return 301 https://example.ru$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name example.ru;

rewrite ^/(favicon.ico)/$ /$1 permanent;

    location ~ ^/(favicon.ico|favicon.ico/) {
        autoindex off;
        root /home/example/example_site/exmaple/example_project/static/images/icons/current/;
        expires 30d;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shokhrov, 2019-06-23
@kot_mapku3

Answering the question in the title,

server {
    listen 80;
    listen [::]:80;
    server_name example.ru www.example.ru;
    location / {
        return 301 https://example.ru$request_uri;
    }
    location = /path/without/redirect {}
    # без =, если другие адреса с этим префиксом тоже не редиректить
}
Even necroposting. Suddenly help someone.
https://stackoverflow.com/a/27866255

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question