LINUX.ORG.RU

Nginx не верно проксирует запрос

 ,


0

1

Есть конфиг nginx:

      location /api/public/login/ {
            proxy_pass      https://req.test.local/api/public/login/;
            proxy_max_temp_file_size 0;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_intercept_errors on;
            error_page 301 302 307 = @handle_redirect;
            }
    
    location /api/protected/new_mnp_request/ {
            proxy_pass      https://req.test.local/api/protected/new_mnp_request/;
            proxy_max_temp_file_size 0;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_intercept_errors on;
            error_page 301 302 307 = @handle_redirect;
            }
    location @handle_redirect {
            set $orig_loc $upstream_http_location;
            proxy_pass $orig_loc;
            set $saved_redirect_location '$upstream_http_location';
    
            set $original_uri $uri;
            set $orig_loc $upstream_http_location;
            proxy_cache_key $original_uri;
    
            proxy_hide_header Strict-Transport-Security;
            proxy_cache_valid 200 202 30h;
            expires 30h;
            access_log off;
            add_header Cache-Control "public";
            etag off;
    
            add_header X-Proxy-Cache $upstream_cache_status;
            }

https://req.test.local - выступает в качестве backend, крутиться на apache и находится на стороне клиента.

На сайте, когда передается запрос на backend, в логах nginx такая ошибка:

2018/11/05 23:06:18 [error] 130606#0: *3 invalid URL prefix in "", client: 10.10.8.28, server: 10.200.210.53, request: "GET /api/public/login?login=mnp_api&password=qs2b_kW%21afs HTTP/1.1", host: "test.local:3443", referrer: "https://test.local:3443/mnp/main"
2018/11/05 23:06:18 [error] 130607#0: *4 invalid URL prefix in "", client: 10.10.8.28, server: 10.200.210.53, request: "GET /api/protected/new_mnp_request?id_location=176&name=1111111111&surname=11111111111&ported_number=7081111111&email=111111111111%40nrer.34&id_lang=1&operator_type=07&patronymic=111111111111&contact_phone=%2B7%28111%29111-11-11 HTTP/1.1", host: "test.local:3443", referrer: "https://test.local:3443/mnp/main"

Соответственно проксирование не работает и в браузере такая ошибка:

:3443/api/public/login?login=mnp_api&password=qq2b_kW%21afs:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
:3443/api/protected/new_mnp_request?id_location=176&name=1111111111&surname=11111111&ported_number=7081111111&email=admin%40test.com&id_lang=1&operator_type=07&patronymic=111111111111&contact_phone=%2B7%28111%29111-11-11:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Подозреваю что ошибка из-за https. Когда оправлять запрос на URL backend через curl сначала срабатывает 301 redirect, а потом уже 200.

Тогда как правильно настроить nginx чтобы проксировалось верно?

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.