D
D
DiGiTAll2017-08-18 20:51:51
Nginx
DiGiTAll, 2017-08-18 20:51:51

How to ignore some folders during global rewrite in nginx config?

There is a website site.ru. There are three folders with scripts in the root: folder1, folder2, folder3.
They must be available via a direct link.
Those. I need to be able to run the site.ru/folder3/script.php script from a browser.
All requests to the main site site must be sent to the script handler.
For example, when requesting:
site.ru/bla-bla-bla
The script should be called:
site.ru/folder1/index.php?get=bla-bla-bla
If I add the Then directive, I will redirect everything. Those. do not access the folder directly. On the Internet, I advise you to register it in location / , but if I replace the data available there, the site starts to issue a 500th error. The current config looks like this:
rewrite ^/(.*)$ /folder1/index.php?get=$1 last;

server {
    server_name site.ru www.site.ru;
    listen 255.255.255.255;
    disable_symlinks if_not_owner from=$root_path;
    set $root_path /var/www/site/data/www/site.ru;
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      root $root_path;
      access_log /var/www/nginx-logs/alishort isp;
      access_log /var/www/httpd-logs/site.ru.access.log ;
      error_page 404 = @fallback;
    }
    location / {

      proxy_pass http://255.255.255.255:81;
      proxy_redirect http://255.255.255.255:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
#

    }



    location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
      proxy_pass http://255.255.255.255:81;
      proxy_redirect http://255.255.255.255:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location @fallback {
      proxy_pass http://255.255.255.255:81;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location ^~ /webstat/ {
      auth_basic "Restricted area";
      auth_basic_user_file /var/www/site/data/etc/1060800.passwd;
      try_files $uri @fallback;
    }
    include /usr/local/ispmgr/etc/nginx.inc;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2017-08-19
@ky0

Make separate locations for directories that should be accessed via a direct link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question