Noktis's avatar

Using Livewire with proxy_pass from different site

Greetings :-)

I have 2 different Docker containers with the main website and Laravel forum. Using proxy_pass in nginx, I'm routing /forum request to another Docker container. Everything works besides system POST request inside Livewire component.

For example, Livewire uses Notifications Provider and tries to reach it every 5 seconds using POST. This particular route always ends up with 404, so it reaches my Laravel-Container, but Laravel doesn't know how to proceed with it, BUT! If I try this request with Postman, it works just fine!!

Error itself (browser console): POST httpexamplecom/forum/livewire/message/layout.notifications 404 (Not Found)

Nginx on the main (website) Docker:

    location /forum/ {
        proxy_pass httpMY_IP:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        rewrite ^/forum/(.*)$ / break;
    }

    location ~ ^/livewire/(.*) {
        proxy_pass httpMY_IP:8081/livewire/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ ^/build/assets/(.*) {
        proxy_pass httpMY_IP:8081/build/assets/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

Log from main site:

site_beta | IP - - [19/Aug/2023:13:48:37 +0000] "POST /forum/livewire/message/layout.notifications HTTP/1.1" 404 6622 "httpexamplecom/forum/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "

Log from forum:

forum_beta    | LOCAL_IP - - [19/Aug/2023:13:48:37 +0000] "POST /livewire/message/layout.notifications HTTP/1.0" 404 6603 "httpexamplecom/forum/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "IP"
forum_beta    | - -  19/Aug/2023:13:48:37 +0000 "POST /index.php" 404

So Laravel becomes this POST-request, passes by proxy, it reaches Laravel's index.php, but it cannot be found by Livewire, but only in browser! I can even open this route (httpexamplecom/forum/livewire/message/layout.notifications) in browser and I see error 419 (method not allowed), but not 404!

I tried:

  1. Rebuilding all containers with different rewrite rules;
  2. Different browsers;
  3. Different app_url, asset_url etc in Livewire.php (config)

I suppose, the problem is not with Docker/nginx/Laravel, it's something wrong with browser JS/script execution, because this request is made from JavaScript file with fetch()... But I have no idea already.

I hope anybody had any idea what should I change and where..

0 likes
0 replies

Please or to participate in this conversation.