详解Nginx 出现 403 Forbidden 的解决办法
Nginx也是当前流行的一款轻量级服务器 在日常使用中呢也会出现一些问题 今天学习君在安装配置Nginx的时候就出现了403Forbindden的被禁止访问的错误 网上搜索之后呢完美解决 这里给大家分享下
话不多说先粘上原版nginx配置文件代码
worker_processes1;
events{
worker_connections1024;
}
http{
includemime.types;
default_typeapplication/octet-stream;
sendfileon;
autoindexon;
keepalive_timeout65;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size128k;
fastcgi_buffers4128k;
fastcgi_busy_buffers_size256k;
fastcgi_temp_file_write_size256k;
#gzipon;
gzipon;
gzip_min_length1k;
gzip_buffers432k;
gzip_http_version1.1;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
gzip_disable"MSIE[1-6].";
server_names_hash_bucket_size128;
client_max_body_size100m;
client_header_buffer_size256k;
large_client_header_buffers4256k;
server{
listen80;
server_namelocalhost;
autoindexon;#是否允许访问目录
root"C:/WWW";
location/{
indexindex.htmlindex.html.php;
#index.php
autoindexon;
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
location~\.php(.*)${
fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
fastcgi_split_path_info^((?U).+\.php)(/?.+)$;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_paramPATH_INFO$fastcgi_path_info;
fastcgi_paramPATH_TRANSLATED$document_root$fastcgi_path_info;
includefastcgi_params;
}
}
includevh_*.conf;
}
这么多配置文件代码(为了便于查看已经把注释的那些不懂的删除) 学习君也是看不懂的
先说403出现的原因
当访问该地址的时候,nginx会按照index.html,index.htm,index.PHP的先后顺序在根目录中查找文件。如果这三个文件都不存在,那么nginx就会返回403Forbidden。
学习君根目录下也是没有这三个文件的所以直接
root"C:/WWW";
location/{
indexindex.htmlindex.html.php;
#index.php
autoindexon;
}
注释 项目列表就展示出来了
这里要注意
autoindexon;这个默认是off的意思是禁止访问目录 需要开启
还有一点推荐大家别把配置项都写在这个文件当中不便于管理
includevh_*.conf;
可以引入这样一个域名一个配置文件方便管理
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。