Laravel Homestead:在 nginx 上禁止 403
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24579107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Homestead: 403 forbidden on nginx
提问by user3710669
I just installed Laravel Homestead according to their instructions. When I open http://homestead.app:8000I get the nginx 403 forbidden HTTP Response.
我只是按照他们的说明安装了 Laravel Homestead。当我打开http://homestead.app:8000 时,我得到了 nginx 403 forbidden HTTP Response。
I have tried setting app/storage permissions to 755, but that didn't work, so I reloaded Vagrant. With no further result.
我曾尝试将应用程序/存储权限设置为 755,但这不起作用,所以我重新加载了 Vagrant。没有进一步的结果。
I also tried changing the nginx configuration, but with no success.
我也尝试更改 nginx 配置,但没有成功。
回答by hdomos
I had the same problem and for me the cause was that in the Homestead.yaml file, I have incorrectly put this:
我遇到了同样的问题,对我来说,原因是在 Homestead.yaml 文件中,我错误地放置了这个:
sites:
- map: homestead.app
to: /home/vagrant/Code
Instead of the correct syntax:
而不是正确的语法:
sites:
- map: homestead.app
to: /home/vagrant/Code/path/to/public
回答by castt
Another reason for this response can be duplicating your routing with folders in public directory. For example you might have homestead.app/lists
GET
route and lists
folder in your /public
directory. This will cause the same 403 error (server will assume you are trying to access /public/lists
directory instead of your /lists
route).
此响应的另一个原因可能是使用公共目录中的文件夹复制您的路由。例如,您的目录中可能有homestead.app/lists
GET
路由和lists
文件夹/public
。这将导致相同的 403 错误(服务器将假定您正在尝试访问/public/lists
目录而不是您的/lists
路由)。
回答by Nathan Gielis
I have been banging my head against the wall dealing with this very same problem, and I just solved it for my case.
在处理同样的问题时,我一直在用头撞墙,而我刚刚为我的案例解决了这个问题。
I was sure I'd set up the yaml file correctly, but I kept getting the 403 error, and when experimenting with some routes I was getting "input file not specified".
我确信我已经正确设置了 yaml 文件,但我一直收到 403 错误,并且在尝试某些路由时,我收到“未指定输入文件”。
My solution came from http://laravel.com/docs/4.2/homesteadand it involved using the serve command. I wasn't adding any additional sites, just trying to anything to get the first site running.
我的解决方案来自http://laravel.com/docs/4.2/homestead,它涉及使用 serve 命令。我没有添加任何额外的站点,只是想尽一切办法让第一个站点运行。
SSH'ing into my vagrant box and using the command "serve my_app_name.app /home/vagrant/Code/path/to/public" did the job. Note that I had already put an entry into my hosts file for this app.
SSH 进入我的流浪箱并使用命令“serve my_app_name.app /home/vagrant/Code/path/to/public”完成了这项工作。请注意,我已经在我的主机文件中为这个应用程序添加了一个条目。
Hope this helps someone.
希望这可以帮助某人。
回答by alexglue
OK, i got the answer to the questionafter few hours of searching and debugging.
OK,我得到答案的问题,搜索和调试的几个小时后。
The problem:
问题:
- I've got GET route /admin
- Also i've got /public/admin/folder with assets inside.
- And i've got 403 access denied from nginx cause of this duplication;
- 我有 GET 路由/admin
- 我还有/public/admin/文件夹,里面有资产。
- 并且我有 403 次访问被 nginx 拒绝,原因是这种重复;
So, if you don't want to rename route or assets folder, all you need to do is replace
所以,如果你不想重命名路由或资产文件夹,你需要做的就是替换
location / {
try_files $uri $uri/ /index.php?$query_string;
# ^^^^^
}
with this:
有了这个:
location / {
try_files $uri /index.php?$query_string;
}
If you could rename your route or assets folder without any refactor then you could do this without nginx config fixing.
如果您可以在不进行任何重构的情况下重命名您的路由或资产文件夹,那么您可以在不修复 nginx 配置的情况下执行此操作。
Hope this will be helpful.
希望这会有所帮助。
回答by MrMesees
For some people this may be as simple as having git cloned in an existing public folder, e.g:
对于某些人来说,这可能就像在现有公共文件夹中克隆 git 一样简单,例如:
- map: hello-world.dev
to: /home/vagrant/Code/Laravel/public/hello-world
The correct folder structure is:
正确的文件夹结构是:
- map: hello-world.dev
to: /home/vagrant/Code/hello-world/public
Another good note is ignoring the laravel docs on editing hosts file, using git shell, or cygwin (windows) to install vagrant hostsupdater, and simply adding entries for hosts and aliases to ~/.homestead/Homestead.yaml file.
另一个注意事项是在编辑主机文件时忽略 laravel 文档,使用 git shell 或 cygwin (windows) 安装 vagrant hostsupdater,并简单地将主机和别名的条目添加到 ~/.homestead/Homestead.yaml 文件。
回答by Mahmoud Zalt
Here's the full solution steps:
以下是完整的解决步骤:
run
homestead edit
add
/public
to the end of your directory
跑
homestead edit
添加
/public
到目录的末尾
sites:
- map: homestead.app
to: /full/path/to/the/laravel-app/public
sites:
- map: homestead.app
to: /full/path/to/the/laravel-app/public
- run
homestead halt && homestead up --provision
- 跑
homestead halt && homestead up --provision
回答by dominiczaq
I would suggest checking the nginx logs - use sudo tail /var/log/nginx/homestead.app-error.log
我建议检查 nginx 日志 - 使用 sudo tail /var/log/nginx/homestead.app-error.log
回答by Abdulaziz Noor
Change the config of Nginx
更改 Nginx 的配置
Put that line in 'location /' section:
将该行放在“位置/”部分:
try_files $uri $uri/public/index.php?$query_string;
If its not working then replace your 'public' with the folder name that content 'index.php',
如果它不起作用,则将您的“public”替换为包含“index.php”的文件夹名称,
That worked great with me using ServerPilot,
使用 ServerPilot 对我来说效果很好,
Good luck!.
祝你好运!。
回答by gk.
In your case, you are getting nginx 403 forbiddenHTTP Response because of improper configuration of sitesin Homestead.yaml
,
if you configure it properly it should work.
在你的情况,你所得到的nginx 403禁止,因为配置不当的HTTP响应站点中Homestead.yaml
,如果配置得当它应该工作。
How to solve the issue step by step:
如何逐步解决问题:
1) Goto your vagrant box and create the laraval app
1) 进入你的 vagrant box 并创建 laraval 应用程序
$vagrant ssh
$cd ~/code
$#lets create basic blog
$laravel new blog
Crafting application...
Loading composer repositories with package information
........
$cd blog
$ll
# You should be able to see public folder in this dir.
# this is the entry point for your application.
# this is your public dir: ~/code/blog/public
# more explicitly: /home/vagrant/code/blog/public
$exit # exit ssh
2) Update the Homestead.yaml with proper site info
2) 使用正确的站点信息更新 Homestead.yaml
- map: homestead.app
to: /home/vagrant/code/blog/public # should be same as in step1
3) Re-provision your vagrant
3)重新配置你的流浪者
$vagrant reload --provision
You should be able to access it now using http://homestead.appThank you!
您现在应该可以使用http://homestead.app访问它了 谢谢!
回答by Lucas Paz
Access in your browser
在浏览器中访问
homestead.app/public
Before installation of laravel/laravel with composer within /home/vagrant/Code/Laravel/public
在/home/vagrant/Code/Laravel/public 中使用 composer 安装 laravel/laravel 之前