i create project with laravel 12 and breeze & inertiajs - React mode
its Ok in localhost but when i push to production i cant send POST,PATCH,DELETE request get error: 419 Page Expired
i send _token from meta header tag
for example login Page:
const {data, setData, post, processing, errors, reset} = useForm({
email: '',
password: '',
remember: false as boolean,
_token: document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'),
});
const submit: FormEventHandler = (e) => {
e.preventDefault();
post(route('login'), {
onFinish: () => reset('password'),
});
};
}
Middleware
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\App\Http\Middleware\HandleInertiaRequests::class,
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
]);
//
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->respond(function (Response $response) {
if ($response->getStatusCode() === 419) {
return back()->with([
'message' => 'The page expired, please try again.',
]);
}
return $response;
});
})->create();
Nginx config
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl-cert.pem;
ssl_certificate_key /etc/nginx/ssl-privateKey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'HIGH:!aNULL:!MD5';
ssl_prefer_server_ciphers on;
server_name domain.com www.domain.com;
root /var/www/domain/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
how can i fix this ?? please help
i try and search a lot but any one have this problem can`t find the sulution;