M
M
Makssof2019-12-04 09:59:04
Nginx
Makssof, 2019-12-04 09:59:04

How to disable redirect to HTTPS in nginx for one address?

There is such a conf:

server{
  listen 80;
  
  location / {
    return 301 https://swight.live$request_uri;
  }
  
  location ~ /bot/ {
    ...
  }
}

server {
  listen 443 ssl;

  location / {
     ...
  }

In other words, you need something that redirects to HTTPS from everywhere, except if the address starts with /bot/
But with the current config, it redirects to https anyway.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynn "Coffee Man", 2019-12-04
@makssof

location ~ /vkbot/ {
    root /home/www/vkbot/;

    try_files $uri $uri/ /index.php?$args;
    index index.php index.html;

    ...
}

The following is written here: if the request contains (and does not start as you want) the string /vkbot/ , then set root /home/www/vkbot/; . The documentation says that the uri from the request is added to the specified path. So, in your request, curl http://swight.live/vkbot/nginx will look for files in the /home/www/vkbot/vkbot/ folder . Not what you wanted, right?
Because of this, try_files will not find anything and will internally redirect to (drumroll) /index.php . After that, nginx will again start looking for a suitable location and will not find anything better than location /in which the redirect is written.
I think it needs to be fixed like this:
location /vkbot/ {
    root /home/www/;

    try_files $uri $uri/ /vkbot/index.php?$args;
    index index.php index.html;

    ...
}

G
Godless, 2019-12-04
@Godless

Try to change again
on the

was wrong
Порядок директив location в конфиге важен!
Попробуйте изменить порядок.

A
Alexey Dmitriev, 2019-12-04
@SignFinder

try moving location = /bot/ in the config above location / (note - there is a sign = =
In general, read about nginx location order priority https://nginx.org/en/docs/http/ngx_http_core_modul...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question