nginx laravel 静态文件访问不到 403

2019-12-01 18:30:03

如果要部署服务器,用nginx,php-fpm,php,一定要注意用户问题,前面几篇文章,我们介绍了如何配置用户。

下面我们要注意的是,一定不要在root文件夹下面部署服务,否则会面临很多异样的问题。

下面我们就因为在root目录下面创建了服务,发生了找不到静态文件的问题,404

参考地址 nginx配置文件里user只能是root,否则报403错误


yum 一个全新的nginx,版本是1.12.2的


直接启动,浏览器输入localhost访问的nginx页面


1、当我将nginx.conf配置文件里root 路径改成/root/html/index.html


#mkdir /root/html

#echo hello > /root/html/index.html

(不用改访问目录权限。不放心对照原始成功的/usr/share/nginx/html/index.html的路径权限)

报错:

root@localhost nginx]# curl localhost

<html>

<head><title>403 Forbidden</title></head>

<body bgcolor="white">

<center><h1>403 Forbidden</h1></center>

<hr><center>nginx/1.12.2</center>

</body>

</html>

查看错误日志:

[root@localhost nginx]# tail -n30 error.log 

2018/01/30 01:35:57 [error] 3511#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"

2018/01/30 01:36:50 [error] 3567#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"

2018/01/30 01:37:20 [error] 3640#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"

2018/01/30 01:38:40 [error] 3640#0: *2 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"

2018/01/30 01:40:27 [error] 3878#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: ::1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "localhost"

2018/01/30 01:40:27 [error] 3878#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: ::1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "localhost"

2018/01/30 01:50:58 [error] 4590#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"



2、再改,将nginx.conf里的user nginx改成

user root;

成功:

[root@localhost ~]# curl localhost

hello

3、不行,我不要将user 变成root,改回来:

user nginx;


重启后,报403的错误。



参考解答:https://stackoverflow.com/questions/31729212/nginx-root-index-html-forbidden-13-permission-denied


4、将访问目录换出root

      我改成了/data/html/index.html

 okokokoko



总结:用户和访问路径不符合。

指定root用户 -----访问路径随便

其他用户(nginx,www)----->访问路径就不可以在/root下



  • 2019-12-06 10:47:29

    date-fns日期工具的使用方法详解

    isToday() 判断传入日期是否为今天 isYesterday() 判断传入日期是否为昨天 isTomorrow() 判断传入日期是否为 format() 日期格式化 addDays() 获得当前日期之后的日期 addHours() 获得当前时间n小时之后的时间点 addMinutes() 获得当前时间n分钟之后的时间 addMonths() 获得当前月之后n个月的月份 subDays() 获得当前时间之前n天的时间 subHours() 获得当前时间之前n小时的时间 subMinutes() 获得当前时间之前n分钟的时间 subMonths() 获得当前时间之前n个月的时间 differenceInYears() 获得两个时间相差的年份 differenceInWeeks() 获得两个时间相差的周数 differenceInDays() 获得两个时间相差的天数 differenceInHours() 获得两个时间相差的小时数 differenceInMinutes() 获得两个时间相差的分钟数

  • 2019-12-06 10:49:39

    npm 查看源 换源

    npm,cnpm,查看源,切换源,npm config set registry https://registry.npmjs.org

  • 2019-12-06 11:01:31

    npm发布包流程详解 有demo

    npm发布包步骤,以及踩过的坑(见红颜色标准): 1.注册npm账号,并完成Email认证(否则最后一步提交会报Email错误) 2.npm添加用户或登陆:npm adduser 或 npm login

  • 2019-12-06 13:16:18

    vue mixins组件复用的几种方式

    最近在做项目的时候,研究了mixins,此功能有妙处。用的时候有这样一个场景,页面的风格不同,但是执行的方法,和需要的数据非常的相似。我们是否要写两种组件呢?还是保留一个并且然后另个一并兼容另一个呢? 不管以上那种方式都不是很合理,因为组件写成2个,不仅麻烦而且维护麻烦;第二种虽然做了兼容但是页面逻辑造成混乱,必然不清晰;有没有好的方法,有那就是用vue的混合插件mixins。混合在Vue是为了提出相似的数据和功能,使代码易懂,简单、清晰。

  • 2019-12-06 13:26:30

    vue的mixins混入合并规则

    混入minxins:分发vue组件中可复用功能的灵活方式。混入对象可以包含任意组件选项。组件使用混入对象时,所有混入对象的选项将混入该组件本身的选项。

  • 2019-12-06 16:50:34

    Intellij idea 如何关闭无用的提示

    Linux:Settings —> Editor —> Inspections —> General —> Duplicated Code Mac:Preferences --> Editor —> Inspections —> General —> Duplicated Code fragment 将对应的勾去掉。

  • 2019-12-09 15:36:56

    神秘的 shadow-dom 浅析,shadow-root

    顾名思义, shadow-dom,直译的话就是 影子dom ?我觉得可以理解为潜藏在黑暗中的 DOM 结构,也就是我们无法直接控制操纵的 DOM 结构。前端同学经常用开发者工具的话,查看 DOM 结构的时候,肯定看到过下面这样的结构:

  • 2019-12-10 11:13:50

    前端实战-基于Nuxt的SVG使用

    虽然我们在日常开发的时候,在使用iview 或者element ui等组件时,通常会包含一些常用icon;但是在面对一些特定的需求时,或者自己想high一下,这些通用的icon并不能很好的满足我们。这个时候我们可能会拿到一些SVG适量图,但是怎么去使用这些矢量图呢。