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-11-25 17:04:10

    Throttle 和 Debounce 的本质及一个简单的实现

    Throttle,Debounce 就不把这两个词翻译成中文了,直接解释他们的概念。实际上这两个东西本质上是一样的,作用都是「为了避免某个『事件』在『一个较短的时间段内』内连续被触发从而引起的其对应的『事件处理函数』不必要的连续执行」。那么区别在哪呢?

  • 2019-11-25 17:05:44

    js实现 throttle 和 debounce,节流,防抖详解

    throttle 节流:drag改变浏览器大小,触发onresize函数,实现拖动每过1秒输出一次,不足1秒,1秒后输出一次。多用于高频操作,如抢票、抢购等,无论点击多少次,只固定间隔执行一次,以减轻压力。debounce防抖:drag改变浏览器大小,触发onresize函数,实现拖动停顿1秒输出。多用于输入框,当某一次输入后停顿满n秒才会去触发远程搜索。

  • 2019-11-25 17:37:01

    百度地图GeoUtils示例

    百度地图JavaScript开源库,是一套基于百度地图API二次开发的开源的代码库。目前提供多个lib库,帮助开发者快速实现在地图上添加Marker、自定义信息窗口、标注相关开发、区域限制设置、几何运算、实时交通、检索与公交驾车查询、鼠标绘制工具等功能。

  • 2019-11-26 11:08:02

    多边型无序点排序(地图绘制多边形)

    任务需求要做一个区域高亮的功能,用到地图,想到了高德地图的多边形API,但是多边形顶点的顺序是要有序的,需求是无序,在API查找无果的情况下,只能手动实现点集合排序。