nginx 訪問圖片上傳伺服器出現403錯誤解決方案
阿新 • • 發佈:2018-12-16
近期在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的狀態。