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

来源:互联网 发布:杨幂赵丽颖谁发展 知乎 编辑:程序博客网 时间:2024/06/10 14:02

安装完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(); ?>` 查看phpinfoecho "<?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 stopnginx

或者:

nginx -s reopen

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

service nginx reload

找到nginx的安装目录:

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

查看nginx的命令提示:

[root@localhost nginx]# nginx -hnginx version: nginx/1.10.2Usage: 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
阅读全文
0 0
原创粉丝点击