tarampampam / nod32-update-mirror

:large_orange_diamond: [WIP] ESET Nod32 Updates Mirror
MIT License
108 stars 50 forks source link

nginx configuration regexp emerg error - unrecognized character in location directive with redirect to correct update.ver #63

Closed roschacker closed 6 years ago

roschacker commented 7 years ago

Шаги для воспроизведения проблемы (steps to reproduce)

Исправил файл конфига по инструкции

  1. listen 80
  2. закомментировал строку с server_name

    запустил тестирование конфигурации

  3. nginx -t

Какое действие ожидалось (expected behaviour)

[root@system ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf  syntax is ok

Что произошло на самом деле (actual behaviour)

[root@system ~]# nginx -t
nginx: [emerg] pcre_compile() failed: unrecognized character after (?< in "^(?<file_url>/update\.ver)$" at "file_url>/update\.ver)$" in /etc/nginx/conf.d/nod32mirror.conf:36
nginx: configuration file /etc/nginx/nginx.conf test failed

Данные системы (system information)

Операционная система (operating system):

[root@system ~]# cat /proc/version
Linux version 2.6.18-308.1.1.v5 (mockbuild@build64-2) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Sun Mar 11 18:15:19 MDT 2012

Bash:

[root@system ~]# bash --version
GNU bash, version 3.2.25(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

wget / curl:

[root@system ~]# wget -V | head -1
GNU Wget 1.11.4 Red Hat modified

[root@system ~]# curl -V
curl 7.15.5 (i386-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Protocols: tftp ftp telnet dict ldap http file https ftps
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

Настройки (settings):

Настройки скрипта (script settings):

[root@system ~]# cat /root/nod32-update-mirror/nod32-mirror/settings.conf  | grep -v -e '^#' -e '^$'
export NOD32MIRROR_MIRROR_DIR="$HOME/nod32mirror";
export NOD32MIRROR_SERVER_0='http://update.eset.com:80/eset_upd/ username password';
export NOD32MIRROR_SERVER_1='http://nod32.someserver.com/';
export NOD32MIRROR_SERVER_2='http://someserver2.com/nod32/';
export NOD32MIRROR_LANGUAGES='1033 1049';
export NOD32MIRROR_CURL_BIN='false';
export NOD32MIRROR_TEST_URI='http://update.eset.com:80/v8-rel-sta/mod_010_smon_1036/em010_32_l0.nup';
export NOD32MIRROR_TIMESTAMP_FILE_NAME='lastevent.txt';
export NOD32MIRROR_VERSION_FILE_NAME='version.txt';

[root@system ~]# cat /etc/nginx/conf.d/*.conf | grep -v -e '^#' -e '^$'                               server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
    location / {
    }
    error_page 404 /404.html;
        location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
server {
  listen      80;
  root        /usr/share/nginx/nod32mirror;
  index       index.html;
  autoindex   on;
  access_log  off;

  # Setting directory names
  set $webface     "webface";
  set $errorspages "errorspages";
  # Setting custom error pages
  error_page 401 /error401.html;
  error_page 403 /error403.html;
  error_page 404 /error404.html;
  error_page 500 /error500.html;
  error_page 502 /error502.html;
  error_page 503 /error503.html;
  location ~ "^/error([\d]{3}\.html)$" {
    try_files /$webface/$errorspages/$1 $uri =404;
  }

  # Deny access for spiders/robots/tools/etc
  if ($http_user_agent ~* ^(wget|aria2|nod32view|perl|php|curl|google|yandex|yahoo|-|mirror|spider|bot|parser|grab)) {
    return 403;
  }
  # Deny direct access for hidden files/directories
  location ~ /\. {
    return 444;
  }

  # Redirect request to correct update.ver file, based on nod32 user-agent version
  location ~* "^(?<file_url>/update\.ver)$" {
    if ($http_user_agent ~* "BPC (?<version>[\d]{1,2})\.") {
      set $new_location "v$version$file_url";
    }
    if (-f $document_root/$new_location) {
      return 301 $scheme://$server_name/$new_location;
    }
  }

  # Enable checking username/password for updates files access
  location ~* ^.+\.nup$ {
    allow all;
    auth_basic "Enter login:password for getting access";
    auth_basic_user_file $document_root/.htpasswd;
  }

  # Redirect empty requests to webface index file
  location = / {
    try_files /$webface/index.html =404;
  }

  try_files $uri /$webface$uri /$webface/$errorspages$uri =404;
}
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.