-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Improved nginx config to not expose other php files #6008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,6 +297,12 @@ The **minimum configuration** to get your application running under Nginx is: | |
# Remove the internal directive to allow URIs like this | ||
internal; | ||
} | ||
|
||
# return 404 for all other php files not matching the front controller | ||
# this prevents access to other php files you don't want to be accessible. | ||
location ~ \.php$ { | ||
return 404; | ||
} | ||
|
||
error_log /var/log/nginx/project_error.log; | ||
access_log /var/log/nginx/project_access.log; | ||
|
@@ -310,10 +316,10 @@ The **minimum configuration** to get your application running under Nginx is: | |
.. tip:: | ||
|
||
This executes **only** ``app.php``, ``app_dev.php`` and ``config.php`` in | ||
the web directory. All other files will be served as text. You **must** | ||
also make sure that if you *do* deploy ``app_dev.php`` or ``config.php`` | ||
that these files are secured and not available to any outside user (the | ||
IP address checking code at the top of each file does this by default). | ||
the web directory. All other files will be denied. You **must** also make | ||
sure that if you *do* deploy ``app_dev.php`` or ``config.php`` that these | ||
files are secured and not available to any outside user (the IP address | ||
checking code at the top of each file does this by default). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this last sentence no longer makes sense, if you do deploy app_dev.php or config.php, a 404 is returned so you don't have to secure it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still the user should be aware of it... If he removes the config above he will get the issue again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, perhaps we should just talk about the end result to avoid.
.. caution::
After you deploy to production, make sure that you **cannot** access the ``app_dev.php``
or ``config.php`` scripts (i.e. ``http://example.com/app_dev.php`` and ``http://example.com/config.php``).
If you *can* access these, be sure to remove the ``DEV`` section from the above configuration. |
||
|
||
If you have other PHP files in your web directory that need to be executed, | ||
be sure to include them in the ``location`` block above. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other files ending in
.php
will be denied.