nginx 访问图片上传服务器出现403错误解决方案

近期在nginx+ftp搭建图片上传服务器的时候,在浏览器访问图片路径出现403错误,经搜集各位大神的回答,整理以下内容:

大家可以按下面的介绍,一一排除自己的问题,欢迎大家指正!

1、首先查看nginx的配置文件

vi /usr/local/nginx/conf/nginx.conf

2、查看首行的user是否更改为和启动用户(root)一致。我这里改成了之前自己设置的ftp用户名ftpuser

user  ftpuser;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}
...

...

3、查看nginx的默认网站根目录,location的配置,我这里设置的是root    /home/ftpuser;就是上传图片存放的地址

   server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           root    /home/ftpuser;
           #root   html;
           #index  index.html index.htm;         
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

4、缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件。

    如果在指定目录下面没有index.php,index.html的时候,直接文件,会报403 forbidden。

server {  

      listen       80;  

      server_name  localhost;  

      index  index.php index.html;  

      root  自己指定的路径;

    }

5、确认index文件是否存在,是否有读写权限,若没有则赋权

1)进入nginx的html路径,cd /自己的路径/nginx/html

2)查看目录下文件和权限,ll

3)有权限跳过,没有赋权chmod 777 -R ./

6、SELinux设置为开启状态(enabled)的原因。

查看当前selinux的状态。

   /usr/sbin/sestatus

将SELINUX=enforcing 修改为 SELINUX=disabled 状态。

    vi /etc/selinux/config     

    #SELINUX=enforcing

    SELINUX=disabled

重启生效。

reboot

最后一条不推荐,我自己的没有改动selinux的状态。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

皓月星辰_w

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

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

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

打赏作者

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

抵扣说明:

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

余额充值