您的位置:首页 > 运维架构 > Nginx

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

2017-06-16 14:44 8621 查看

安装完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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html nginx
相关文章推荐