Home >Operation and Maintenance >Nginx >Why does nginx appear 403

Why does nginx appear 403

步履不停
步履不停Original
2019-06-21 13:18:177066browse

Why does nginx appear 403

Nginx is also a popular lightweight server. Some problems may occur in daily use. Today, when installing and configuring Nginx, it appeared. 403 Forbindden was The error of prohibiting access was solved perfectly after searching online. I will share it with you here.

Without further ado, here’s the original nginx configuration file code:

[plain] view plain copy
worker_processes  1;  
  
events {  
    worker_connections  1024;  
}  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
      
    sendfile        on;  
    autoindex       on;  
    keepalive_timeout  65;  
  fastcgi_connect_timeout 300;  
  fastcgi_send_timeout 300;  
  fastcgi_read_timeout 300;  
  fastcgi_buffer_size 128k;  
  fastcgi_buffers 4 128k;  
  fastcgi_busy_buffers_size 256k;  
  fastcgi_temp_file_write_size 256k;  
  
  #gzip  on;  
  gzip on;  
  gzip_min_length  1k;  
  gzip_buffers     4 32k;  
  gzip_http_version 1.1;  
  gzip_comp_level 2;  
  gzip_types       text/plain application/x-javascript text/css application/xml;  
  gzip_vary on;  
  gzip_disable "MSIE [1-6].";  
  
  server_names_hash_bucket_size 128;  
  client_max_body_size     100m;   
  client_header_buffer_size 256k;  
  large_client_header_buffers 4 256k;  
  
    server {  
        listen       80;  
        server_name  localhost;  
        autoindex       on;   #是否允许访问目录  
  
        root   "C:/WWW";  
        location / {  
            index  index.html index.htm  l.php;  
            #index.php  
           autoindex  on;  
        }  
        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {  
            root   html;  
        }  
  
        location ~ \.php(.*)$  {  
            fastcgi_pass   127.0.0.1:9000;  
            #fastcgi_index  index.php;  
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;  
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
            fastcgi_param  PATH_INFO  $fastcgi_path_info;  
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;  
            include        fastcgi_params;  
        }  
  
    }  
  
include vh_*.conf;  
  
}


So many configuration file codes (the comments that I don’t understand have been deleted for ease of viewing)

Let’s talk about the reasons why 403 appears

When accessing this address, nginx will follow the order of index.html, index.htm, and index.php. Find the file in the root directory. If none of these three files exist, nginx will return 403Forbidden.

Because there are no these three files in the root directory, so directly

[plain] view plain copy
root   "C:/WWW";  
  location / {  
      index  index.html index.htm  l.php;  
      #index.php  
     autoindex  on;  
  }

Comment: The project list is displayed

Be careful here

autoindex on; This default is off, which means that access to the directory is prohibited and needs to be turned on

It is also recommended that you do not write all configuration items in this file, which is not easy to manage

[plain] view plain copy

include vh_*.conf;

can be introduced, so that one domain name and one configuration file are convenient for management.

For more Nginx related technical articles, please visit the Nginx Tutorial column to learn!

The above is the detailed content of Why does nginx appear 403. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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

Related articles

See more