linux权限问题

I try to deploy the gitbook on my remote server , but there are something difficult:

"2025/07/24 00:20:22 [crit] 3851475#3851475: *1 stat() "/home/lighthouse/mini-kv-gitbook/_book/" failed (13: Permission denied), client: 111.210.24.14, server: 212.64.0.27, request: "GET / HTTP/1.1", host: "212.64.0.27:3000"

13:Permission denied represent WWW-DATA,the user of Nginx, haven't sufficient permissions to access /home/lighthouse/mini-kv-gitbook/_book/ directory,then ChatGPT give the solution:

sudo chmod +x /home /home/lighthouse /home/lighthouse/mini-kv-gitbook
sudo chown -R www-data:www-data /home/lighthouse/mini-kv-gitbook

in short,chmod stands "change mode", and chown stands "change owner".

chmod sets the permissions for files and directories. The +x flag adds "execute" permissions to the directories, allowing users (like Nginx) to access the contents of those directories. This is crucial because directories require "execute" permissions to be traversed.

chown changes the ownership of files and directories. By setting the owner to www-data, Nginx (which runs under www-data) will be able to read, write, and execute files in /home/lighthouse/mini-kv-gitbook/_book/.

We grant "execute" permissions (+x) to the directories /home, /home/lighthouse, and /home/lighthouse/mini-kv-gitbook, allowing all users (including www-data) to access them. Additionally, we change the ownership of /home/lighthouse/mini-kv-gitbook to www-data so that Nginx can read and serve the files.

But what's the '-x' means?

Fortunately, in the operating system course, I learned some basics. For example, the ls -l output drwxr-xr-- respectively represent:

  • In this file,the owner could rwx(read,write,execute)
  • the groups of owner could r-x(read and execute)
  • the others could r--(read only)

the essence of chmod +x is transform drwxr-xr-- to drwxr-xr-x.That is to say,all the user have permissions to execute. In summary, adding "execute" permissions to directories allows users (including Nginx) to access the contents of those directories. By changing the ownership to www-data, we ensure that Nginx has the necessary permissions to read, write, and execute the files, allowing the GitBook to be served successfully.

posted @ 2025-07-24 16:13  seekerHeron  阅读(16)  评论(0)    收藏  举报