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

kbs1234's avatar

Nginx deployment clarification - security

Regarding nginx deployment outlined in documentation (/docs/10.x/deployment#nginx), what is the particular benefit of this directive?

location ~ \.php$ {

Since Laravel only contains index.php in the public directory, is it safe to replace this directive with the following one?

location = /index.php {

The latter would only allow executing index.php as PHP code, this could increase security if, for example, an attacker would be able to drop any other PHP file in your public directory tree using any means.

What are your opinions on this? Thank you a lot in advance.

0 likes
4 replies
jlrdw's avatar

That is the fastcgi section.

kbs1234's avatar

No, it's main "server" configuration, from the docs, laravel.com/docs/10.x/deployment#nginx

kbs1234's avatar

It works, I just want to know if there are some downsides to it. I think it might be better for security, but then I'm not sure why the official manual allows executing any PHP files in public directory besides index.php

Please or to participate in this conversation.