近期在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的状态。