首頁  >  文章  >  運維  >  nginx為什麼會出現403

nginx為什麼會出現403

步履不停
步履不停原創
2019-06-21 13:18:176778瀏覽

nginx為什麼會出現403

Nginx也是目前流行的一款輕量級伺服器,在日常使用中呢也會出現一些問題,今天在安裝配置Nginx的時候就出現了,403 Forbindden的被禁止訪問的錯誤,網路搜尋之後完美解決,這裡跟大家分享下。

話不多說先黏上原版nginx 設定檔程式碼:

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


這麼多設定檔程式碼(為了方便查看已經把註解的那些不懂的刪除)

先說403出現的原因

當造訪該位址的時候,nginx會依照index.html,index.htm,index.php的先後順序在根目錄中尋找檔案。如果這三個檔案都不存在,那麼nginx就會回傳403Forbidden。

因為根目錄下也是沒有這三個檔案的,所以直接

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

註解:專案清單就展示出來了

這裡要注意

autoindex on; 這個預設是off的,意思是禁止存取目錄,需要開啟 

還有一點推薦大家別把設定項,都寫在這個檔案當中,不便於管理 

[plain] view plain copy

include vh_*.conf;  

可以引入,這樣一個網域一個設定文件,方便管理。

更多Nginx相關技術文章,請造訪Nginx教學欄位學習!

以上是nginx為什麼會出現403的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn