#nginx #location #match
#nginx #Расположение #совпадение
Вопрос:
Используя приведенную ниже nginx conf, я, похоже, не могу найти /api/v2/macs/ , а скорее он переходит в /api/. Проблема в том, что я пробовал один и тот же conf в нескольких средах, и он не работает только в моей основной производственной среде. Есть идеи?
server {
listen 80 default_server;
client_max_body_size 0;
charset UTF-8;
proxy_read_timeout 300;
proxy_intercept_errors on;
error_page 403 /403;
error_page 404 /404;
error_page 502 /502;
server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
image/svg xml;
# Serve index.html
location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex off;
error_page 404 /404;
# Cache busting
if_modified_since off;
expires -1;
}
location /api/v2/macs/ {
rewrite ^/api/v2/macs/(.*) /$1 break;
proxy_pass http://my-server:80;
}
#
# API
#
location /api/ {
rewrite ^/api/(.*) /api/$1 break;
proxy_pass http://other-server;
}
#
# Ping
#
location = /ping {
return 200;
}
#
# Errors
#
location = /403 {
root /usr/share/nginx/html/templates/error;
index 403.html;
}
location = /404 {
root /usr/share/nginx/html/templates/error;
index 404.html;
}
location = /502 {
root /usr/share/nginx/html/templates/error;
index maintenance.html;
}
}
Насколько я понимаю, nginx должен соответствовать, используя самый длинный префикс перед остановкой, но это не то, что происходит.
Спасибо!
Комментарии:
1.
location = /api/v2/macs/
не является местоположением префикса. Удалите=
, если вам нужно местоположение с префиксом. Смотрите этот документ .2. Спасибо, Ричард. На самом деле это была опечатка с моей стороны, потому что я экспериментировал с разными решениями. Я удалил =, и он все еще не совпадает. Любые другие предложения?