Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jwhoami's avatar

Has anyone got livewire 3 running in production on a NGINX Server

Hi

I am getting NGINX 404 for the livewire/update endpoint on livewire version 3.

The same application runs fine on my dev machine using sail but fails when moved to a cloud server using NGINX

I followed the livewire 3 installation guide.

I added to routes/web.php file

Livewire::setUpdateRoute(function ($handle) { return Route::post('/livewire/update', $handle); });

artisan route:list shows

POST livewire/update .......................................................... livewire.update › Livewire\Mechanisms › HandleRequests@handleUpdate

Any ideas.

Thanks

0 likes
6 replies
LaryAI's avatar
Level 58

It sounds like the issue you're experiencing with Livewire 3 on your NGINX server might be related to the server configuration, specifically the way NGINX is handling requests to the /livewire/update endpoint.

Here's a checklist to ensure that your NGINX configuration is set up correctly to handle Livewire requests:

  1. Check NGINX Configuration for try_files Directive: Ensure that your NGINX server block for the site includes the try_files directive to pass all requests to the index.php file, which is necessary for pretty URLs and to ensure that Livewire's internal routing works correctly.

    Your NGINX configuration should include something like this:

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
  2. Ensure index.php is Correctly Configured: Double-check that the index.php file is correctly set as the entry point for your application in the NGINX configuration.

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Ensure this points to your PHP-FPM socket
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
  3. Check for Correct Headers: Livewire requires certain headers to be passed correctly. Ensure that your NGINX configuration is not stripping out headers that Livewire might need.

  4. File Permissions: Verify that the file permissions on the server allow the web server user to read and execute the necessary files.

  5. Clear Caches: Sometimes, old cached routes or configurations can cause issues. Make sure to clear your Laravel application cache, route cache, and config cache. You can do this by running the following Artisan commands:

    php artisan cache:clear
    php artisan route:clear
    php artisan config:clear
    php artisan view:clear
    
  6. Check NGINX Error Logs: Review the NGINX error logs for any specific messages that might indicate what the problem is. The error logs are typically located in /var/log/nginx/error.log.

  7. Livewire JavaScript Assets: Ensure that Livewire's JavaScript assets are properly included in your layout and that they are accessible. If these assets are not loaded correctly, Livewire will not function.

If after going through this checklist you're still experiencing issues, it might be helpful to provide more specific details about your NGINX configuration and any error messages you're seeing in the logs. This will help in diagnosing the problem more accurately.

aurawindsurfing's avatar

@jwhoami

I change my answer. The only thing I can think of is you not having SSL certificate on your production server and therefore having browser error. Check your console.

Snapey's avatar

It will break if you don't correctly set the document root to be the public folder.

if you are seeing public in your page URLS then the setup is wrong.

jwhoami's avatar

I do have ssl certificate configured and running fine. And livewire is working except for the update endpoint.

I dont think its a livewire thing yet. I think its more in line with what Lary said, its nginx thing and this is why I think so:

Nginx is not even passing the request to livewire when it sees the /livewire/update endpoint.

My nginx configuration is as follows: ` server {

root /home/www/ciemi/app/public;

index index.html index.htm index.nginx-debian.html index.php;

server_name example.com; (not showing the real domain name for security)

location / {
	try_files $uri $uri/ /index.php?$query_string =404;
}

location ~ \.php$ {

	include snippets/fastcgi-php.conf;

	fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
}

location ~ /\.ht {

	deny all;

}

listen [::]:443 ssl; # managed by Certbot

listen 443 ssl; # managed by Certbot

ssl_certificate /etc/letsencrypt/live/ciemi/fullchain.pem; # managed by Certbot

ssl_certificate_key /etc/letsencrypt/live/ciemi/privkey.pem; # managed by Certbot

include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

`

I enabled debug on nginx and see the following: ` 2023/12/05 10:31:47 [debug] 16981#16981: *440 http script var: "/livewire/update"

2023/12/05 10:31:47 [debug] 16981#16981: *440 trying to use file: "/livewire/update" "/home/www/ciemi/app/public/livewire/update"

2023/12/05 10:31:47 [debug] 16981#16981: *440 http script var: "/livewire/update"

2023/12/05 10:31:47 [debug] 16981#16981: *440 trying to use dir: "/livewire/update" "/home/www/ciemi/app/public/livewire/update"

2023/12/05 10:31:47 [debug] 16981#16981: *440 http script copy: "/index.php?"

2023/12/05 10:31:47 [debug] 16981#16981: *440 trying to use file: "/index.php?" "/home/www/ciemi/app/public/index.php?"

2023/12/05 10:31:47 [debug] 16981#16981: *440 trying to use file: "=404" "/home/www/ciemi/app/public=404"

2023/12/05 10:31:47 [debug] 16981#16981: *440 http finalize request: 404, "/livewire/update?" a:1, c:1

2023/12/05 10:31:47 [debug] 16981#16981: *440 http special response: 404, "/livewire/update?" `

The file /home/www/ciemi/app/public/index.php does exist

root@ciemi:/home/www/ciemi/app# ls -l /home/www/ciemi/app/public/index.php -rw-rw-r-- 1 sysadmin www-data 1710 Dec 2 14:41 /home/www/ciemi/app/public/index.php

However going by the log files, nginx is not picking up the index.php on try_files and forwarding it to the php location.

Thanks again

akrasteva's avatar

I had a similar issue, and I solved, by changing the custom route, removing the DOT js

Livewire::setScriptRoute(function ($handle) { return Route::get('/livewire/livewirejs', $handle); });

Now nginx doesn't try to reach the file and goes directly to the route. Maybe is not related, but I think worth sharing for future searches.

1 like
MobyDuck's avatar

My nginx config was trying to serve JS files locally and not forwarding the request over to php.

Publishing the assets into /public/vendor/livewire via artisan vendor:publish --tag=livewire:assets solved this for me, and adding that command into the composer.json should keep it updated.

"post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi",
            "@php artisan vendor:publish --tag=livewire:assets --ansi"
        ],

"post-install-cmd": [
            "@php artisan vendor:publish --tag=livewire:assets --ansi"
        ]

Not strictly the issue the OP was having, but this discussion came up top in Google while I was searching for answers so I thought I'd mention it.

1 like

Please or to participate in this conversation.