由於某些原因無法更改 nginx 上的 root

由於某些原因無法更改 nginx 上的 root

由於某種原因我無法更改根。我與 上的預設根目錄具有相同的權限/usr/share/nginx/html,並且我還755對其他資料夾中的所有檔案和資料夾具有遞歸權限。我什至嘗試將用戶和群組更改為 root 和 nginx,看看是否有任何區別,但事實並非如此。我不斷得到403 禁忌

所以基本上我做了這個資料夾

$ mkdir -p /srv/www/test.com/public_html

$ vi /srv/www/test.com/public_html/index.html

$ vi /srv/www/test.com/public_html/test.php

$ chmod -R 755 /srv/www/test.com/public_html

嘗試將使用者和群組更改為nginx

$ chown -R nginx:nginx /srv/www

配置主conf文件

$ vi /etc/nginx/nginx.conf

這就是我的配置的樣子,包含內容被註解掉

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;   
pid        /run/nginx.pid;

events {
    worker_connections  1024;
}

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    index index.php index.html index.htm;

    server {

        listen       80;
        server_name  _;
        root /srv/www/test.com/public_html;
        # root  /usr/share/nginx/html;

        location / {
                autoindex on;
        }

        error_page  404 /404.html;

        location = /40x.html { }


        error_page   500 502 503 504  /50x.html;

        location = /50x.html { }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass   unix:/var/run/php-fpm/www.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

    }

}       

一切都在註解掉的預設根資料夾中運行,但是當我更改根目錄時,我收到 403 禁止。我覺得我已經嘗試了一切,改變使用者和檔案權限等等。 php-fpm 將 nginx 作為使用者和群組。並且在main.conf檔案中將使用者設定為nginx。我只使用這個檔案來設定 nginx,並將包含內容註解掉。

我不知道該怎麼做。現在已經被困了幾個小時了。任何幫助將不勝感激

答案1

為了清楚起見,我將我的評論作為答案發布,這是由 SELinux 引起的,並將策略模式設置為寬鬆semanage permissive -a httpd_t是其中之一“又快又髒“ 解決方案。

乾淨的解決方案是設定 SELinux 上下文chcon -Rt httpd_sys_content_t /srv/www/test.com並尋找潛在的新 SELinux 投訴(如果有)(取決於您接下來在設定檔中設定的內容)。

相關內容