How to solve 403 caused by Nginx website root directory change

WBOY
Release: 2023-05-18 10:28:12
forward
1114 people have browsed it

1. Change the root directory

nginx default website root directory is /usr/local/nginx/html, you need to change it to /home/fuxiao/www

Change method:

vi /usr/local/nginx/conf/nginx.conf
Copy after login

Change

location / {
      root  html;
      index index.php index.html index.htm;
    }
Copy after login

to

location / {
      root  /home/fuxiao/www;
      index index.php index.html index.htm;
    }
Copy after login

Then change

location ~ \.php$ {
      root      html;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param script_filename $document_root$fastcgi_script_name;
      include    fastcgi_params;
    }
Copy after login

to

location ~ \.php$ {
      root      /home/fuxiao/www;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param script_filename $document_root$fastcgi_script_name;
      include    fastcgi_params;
    }
Copy after login

and then restart nginx. The root directory of the website is already our home www in the directory.

2. Solve the 403 error

But after the change is completed and tested, when accessing the web page under www, it always prompts 403 forbidden, as shown below

How to solve 403 caused by Nginx website root directory change

Solution

At first I thought that the webpage I visited did not have read permission, so I granted read permission to the webpage, but after changing it, I still got the error when I visited it again. After trying a variety of methods, I found that the problem was that fuxiao in the /home/fuxiao directory did not have read permissions. That is, our ordinary users did not have read permissions at first. We only need to grant read permissions to the directory to solve the 403 problem.

The above is the detailed content of How to solve 403 caused by Nginx website root directory change. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template