directory index of "/usr/share/nginx/html/" is forbidden

109 篇文章 7 订阅

安装完nginx之后访问本机ip,结果直接报错,然后去查看nginx错误日志,看到如下错误信息,意思是html下面没有

directory index of "/usr/share/nginx/html/" is forbidden

1、如果在/usr/share/nginx/html下面没有index.php,index.html的时候,直接访问域名,找不到文件,会报403 forbidden。

解决办法:直接输入以下命令:

#删除index.html文件
rm /usr/share/nginx/html/index.html
#在html目录下面新建一个index.php文件,内容是`<?php phpinfo(); ?>` 查看phpinfo
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php

2、还有一个原因就是你的默认的nginx配置文件的location没有指定root路径,我的就是这个问题。

这个就直接在默认的server上面加上:

location / {
    root   html;
    index  index.php index.html index.htm;
}

3、如果还是不能正常访问,那就进到nginx的默认配置文件里去找一下,看看有没有如下代码:

location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}
上面代码的意思是把php文件交给php-fpm处理,php-fpm占用的端口号是9000

配置完以后,记得重启nginx,或者reload一下:

重启nginx:

nginx -s stop
nginx

或者:

nginx -s reopen

下面是重新加载nginx的配置文件(推荐这种方式):

service nginx reload

找到nginx的安装目录:

[root@localhost nginx]# which nginx
/usr/sbin/nginx             #这个是yum安装后默认所在位置

查看nginx的命令提示:

[root@localhost nginx]# nginx -h
nginx version: nginx/1.10.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/share/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file
  • 11
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值