Complete steps to solve 403 forbidden in Nginx

Complete steps to solve 403 forbidden in Nginx

The webpage displays 403 Forbidden

Nginx (yum installation log is usually in /var/log/nginx/error.log) error log display

open() "/web/www/one.txt" failed (13: Permission denied), client: 192.168.1.110, server: rumenz.com, request: "GET /one.txt HTTP/1.1", host: "rumenz.com"

There are four reasons for this:

  1. SELinux is not disabled
  2. Nginx startup user and working user are inconsistent
  3. The directory where the webpage is located has incorrect permissions
  4. Missing default homepage

Solution:

SELinux is not disabled

1.1 Temporarily disable SELinux, but it will be enabled again after restarting the operating system

setenforce=0

1.2 Permanently disable SELinux

vim /etc/selinux/config

Change SELINUX=enforcing to SELINUX=disabled

Nginx startup user and working user are inconsistent

[root@rumenz#]ps aux | grep "nginx: worker process" | awk '{print $1}'
nobody
root

Modify Nginx configuration file

vim /etc/nginx/nginx.conf

Change user nobody to user root; restart Nginx

Note: The startup user and working user of Nginx can be different, but the permissions of the web directory must be configured so that the working user has the permission to access the web directory

Directory permissions issue where the web page is located

3.1 Fine-grained control: The root directory of the web page must have x permissions (that is, you can cd into it), and the parent directory where the web page is located must have r (read permission)

3.2 Simple and crude (not recommended, unsafe, but effective):

chmod -R 777 /web
chmod -R 777 /web/www

Missing default homepage

4.1 After the permissions are assigned, why does the homepage still show 403 Forbidden?

4.2 The root directory of the webpage provides a default homepage: index.html

This is the end of this article about how to solve 403 forbidden with Nginx. For more information about how to solve 403 forbidden with Nginx, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to Nginx 403 Forbidden error caused by permission problem
  • Solution to Nginx 403 forbidden
  • Nginx 403 Forbidden Final Solution
  • Solution to Nginx reporting 403 forbidden error (13: Permission denied)
  • Detailed explanation of the solution to 403 Forbidden in Nginx
  • Solution to the problem of changing the root directory of Nginx website and causing 403 forbidden

<<:  Vue custom encapsulated button component

>>:  Differences between MySQL MyISAM and InnoDB

Recommend

Vue Element-ui implements tree control node adding icon detailed explanation

Table of contents 1. Rendering 2. Bind data and a...

Detailed explanation of MySQL database transaction isolation levels

Database transaction isolation level There are 4 ...

Introduction to the use of MySQL source command

Table of contents Thoughts triggered by an online...

Datagrip2020 fails to download MySQL driver

If you cannot download it by clicking downloadlao...

SQL Aggregation, Grouping, and Sorting

Table of contents 1. Aggregate Query 1. COUNT fun...

Vue implements Tab tab switching

This article example shares the specific code of ...

sql script function to write postgresql database to implement parsing

This article mainly introduces the sql script fun...

Security considerations for Windows server management

Web Server 1. The web server turns off unnecessar...

MySQL group query optimization method

MySQL handles GROUP BY and DISTINCT queries simil...

How to understand JavaScript modularity

Table of contents 1. Browser support 2. export ex...

MySQL series of experience summary and analysis tutorials on NUll values

Table of contents 1. Test Data 2. The inconvenien...

How to get the real path of the current script in Linux

1. Get the real path of the current script: #!/bi...