Home  >  Article  >  Operation and Maintenance  >  How to solve 403 caused by Nginx website root directory change

How to solve 403 caused by Nginx website root directory change

WBOY
WBOYforward
2023-05-18 10:28:121069browse

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

Change

location / {
      root  html;
      index index.php index.html index.htm;
    }

to

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

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;
    }

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;
    }

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete