如何隐藏配置文件以防止直接访问? [英] How to hide config files from direct access?
本文介绍了如何隐藏配置文件以防止直接访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 Laravel 用于网络应用程序.上传生产中的所有内容,发现某些文件可以通过 url 直接访问 - 例如 http://example.com/composer.json
I am using Laravel for web app. Uploaded everything on production and found out that some of the files can be directly accessed by url - for example http://example.com/composer.json
如何避免直接访问?
推荐答案
您使用了错误的 Web 服务器配置.将您的 Web 服务器指向 public
目录并重新启动它.
You're using wrong web server configuration. Point your web server to a public
directory and restart it.
对于 Apache,您可以使用以下指令:
For Apache you can use these directives:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
对于 nginx,你应该改变这一行:
For nginx, you should change this line:
root /path_to_laravel_project/public;
这样做之后,所有 Laravel 文件将无法再从浏览器访问.
After doing that, all Laravel files will not be accessible from browser anymore.
这篇关于如何隐藏配置文件以防止直接访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文