A
A
Artem2021-02-25 11:43:21
Nginx
Artem, 2021-02-25 11:43:21

Why is the request not being proxied?

Hello.

An application is raised in the docker, at the entrance of which is nginx with the following config:

server {
    listen 80;
    server_name my.localhost;

    location ^/cdn/ {
        proxy_pass http://app:8082/;
   }

    location ^/api/ {
        proxy_pass http://app:8081/;
   }

    location / {
        proxy_pass http://app:8080;
    }
}
server {
    listen 80;
    server_name cdn.localhost;
    location / {
        proxy_pass http://app:8082;
    }
}
server {
    listen 80;
    server_name internal-api.localhost;
    location / {
        proxy_pass http://app:8081;
    }
}


The app domain is monitored by apache with the following config:
<VirtualHost *:8080>
    ServerName 127.0.0.1
    DocumentRoot "/app/frontend/web/"

    <Directory "/app/frontend/web/">
        DirectoryIndex index.html
        Require all granted

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.html [L]
    </Directory>

    LogLevel debug
</VirtualHost>

<VirtualHost *:8081>
    ServerName 127.0.0.1
    DocumentRoot "/app/api/web/"

    <Directory "/app/api/web/">
        # use mod_rewrite for pretty URL support
        RewriteEngine on
        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward the request to index.php
        RewriteRule . index.php

        # use index.php as index file
        DirectoryIndex index.php

        # ...other settings...
        # Apache 2.4
        Require all granted

        ## Apache 2.2
        # Order allow,deny
        # Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:8082>
    ServerName 127.0.0.1
    DocumentRoot "/app/static/web/"

    <Directory "/app/static/web/">
        # use mod_rewrite for pretty URL support
        RewriteEngine on
        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward the request to index.php
        RewriteRule . index.php

        # use index.php as index file
        DirectoryIndex index.php

        # ...other settings...
        # Apache 2.4
        Require all granted

        ## Apache 2.2
        # Order allow,deny
        # Allow from all
    </Directory>
</VirtualHost>


When I send a request to my.localhost/api/... I get this 500 from apache
dj_weo__6goovfyufffmskex398.png
. The following is in the logs:
app_1     | [Thu Feb 25 08:39:46.175271 2021] [authz_core:debug] [pid 16] mod_authz_core.c(820): [client 172.27.0.5:54222] AH01626: authorization result of Require all granted: granted
app_1     | [Thu Feb 25 08:39:46.175332 2021] [authz_core:debug] [pid 16] mod_authz_core.c(820): [client 172.27.0.5:54222] AH01626: authorization result of <RequireAny>: granted
app_1     | [Thu Feb 25 08:39:46.176128 2021] [core:error] [pid 16] [client 172.27.0.5:54222] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
app_1     | [Thu Feb 25 08:39:46.176153 2021] [core:debug] [pid 16] core.c(3833): [client 172.27.0.5:54222] AH00121: r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176159 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176164 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176170 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176176 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176183 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176187 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176193 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176199 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176205 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /index.html
app_1     | [Thu Feb 25 08:39:46.176212 2021] [core:debug] [pid 16] core.c(3840): [client 172.27.0.5:54222] AH00122: redirected from r->uri = /api/


The question is, how does the request get to app:8080 if nginx should have been proxied to app:8081?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-02-25
@dodo512

location ^/api/ {
    proxy_pass http://app:8081/;
}

location / {
    proxy_pass http://app:8080;
}

If you wanted to set a regular expression, then you forgot to add If you need a regular prefix location, then you need to remove the extra~
location ~ ^/api/ {
location /api/ {

F
Fenrir89, 2021-02-25
@Fenrir89

VirtualHost *: 8080
After * it does not look for other occurrences, for it it is a complete hit in the domain, write ip or name instead of *

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question