小知识:详解Nginx 出现 403 Forbidden 的解决办法

Nginx 也是当前流行的一款 轻量级服务器  在日常使用中呢 也会出现一些问题  今天 学习君 在安装配置Nginx的时候就出现了 403 Forbindden 的被禁止访问的错误   网上搜索之后呢 完美解决  这里给大家分享下

话不多说 先粘 上 原版nginx 配置文件代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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就会返回403 Forbidden。

学习君根目录下也是没有这三个文件的 所以直接

?
1
2
3
4
5
6
root  “C:/WWW”;
location / {
index index.html index.htm l.php;
#index.php
autoindex on;
}

注释   项目列表就展示出来了

这里要注意

autoindex on; 这个默认是off的 意思是禁止访问目录  需要开启

还有一点推荐大家别把配置项 都写在这个文件当中 不便于管理 

?
1
include vh_*.conf;

可以引入这样一个域名一个配置文件方便管理

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/zhexienianlai/article/details/54091479

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Linux 命令 su 和 sudo 的区别

2023-4-22 3:52:34

建站知识

小知识:如何在 Linux 上杀死一个僵尸进程

2023-4-22 4:01:13

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索