nginx靜態資源文件無法訪問,403 forbidden錯誤

在安裝 nginx 服務器後,我想把網站的根目錄設置爲 /root/www/ ,於是對 nginx 的 nginx.conf 文件進行配置

先打開 nginx.conf

user  www www
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
    
        charset utf-8;
    
        #access_log  logs/host.access.log  main;
    
        location / {
            root   /root/www/;          ## 設置的地方
            index  index.html index.htm;
        }
            
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }    
        }
}

保存後,重啓 nginx 服務,然後出現了 403 錯誤

網上查詢後說是權限問題,更改 nginx.conf 的第一行
將 user www www; 改爲 user root;

保存,再次重啓 nginx 服務,訪問成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章