z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

laravel admin 访问后台403 Forbidden nginx/1.10.3 (Ubuntu);非要加indexphp/admin 才行 #2134

Closed dengyupeng closed 6 years ago

dengyupeng commented 6 years ago

laravel -admin安装后(laravel 是5.5版本),访问http://localhost:8000/admin/ 报错:403 Forbidden nginx/1.10.3 (Ubuntu);

需要这样才可以:http://localhost:8000/index.php/admin/
这个怎么解决的呀?有遇到一样问题的吗?

dengyupeng commented 6 years ago

知道这个问题的原因了,刚才发现了,我在public 下面建立了admin文件夹 就出现上面的问题。 我是这样区分的:但是public下面有admin文件夹 访问:http://localhost:8000/admin/ 就会出现 403 Forbidden nginx/1.10.3 (Ubuntu);

public admin
css
js
img
lib
     home
     |         |
     |        css
     |        js
     |        img
     |        lib 
     css
      js
      img
      lib

这个问题也是无意中侥幸发现的。

dengyupeng commented 6 years ago

image suan算了,还是不叫admin/Admin。如果这样叫 有时候还是会出现问题。

noogen commented 6 years ago

@dengyupeng please post your nginx config for help with troubleshooting nginx. These are what I use as example:

nginx to phpfpm: https://github.com/niiknow/vestacp/blob/master/rootfs/sysprepz/nginx-templates/php-fpm.stpl nginx - proxy to - apache (simply proxy pass it directly into apache): https://github.com/serghey-rodin/vesta/blob/master/install/ubuntu/16.04/templates/web/nginx/default.stpl#L10

I'm guessing you're using phpfpm so...

P.S. You seem to have permission issue so you may want to check all your folder permissions and the nginx user permission first before reading further.

TLDR

breaking down what is required from the nginx configuration template by line

  1. https://github.com/niiknow/vestacp/blob/master/rootfs/sysprepz/nginx-templates/php-fpm.stpl#L13 You need to set your document root to the public/ folder. The base folder is only for debug with artisan (see server.php) comment.
  2. https://github.com/niiknow/vestacp/blob/master/rootfs/sysprepz/nginx-templates/php-fpm.stpl#L23 This line say to try finding the file first, if not found, then fallback to use index.php and don't forget about query string.
  3. https://github.com/niiknow/vestacp/blob/master/rootfs/sysprepz/nginx-templates/php-fpm.stpl#L30 this line and the rest of the lines below it are fpm configuration for the ".php" extension file group.

Therefore, if you add an admin folder, then that would overwrite the default laravel-admin routing of "/admin"

Again:

  1. Check file system permission and nginx user can access to those folder.
  2. Check if document root is correctly setup.
  3. If you have a folder, check that you're not overwriting any default route. Check that you have an index.php file under that folder if you do not have directory browsing on.