【问题标题】:nginx 403 forbidden under Debian 7Debian 7下禁止nginx 403
【发布时间】:2013-07-04 07:51:21
【问题描述】:

我在装有 Debian 7 的笔记本电脑上遇到 403 禁止错误

文件权限为 775:chmod 775 -R /var/www

nginx错误日志显示:

2013/07/05 16:27:06 [错误] 7351#0: *12 目录索引 “/var/www/install/”被禁止,客户端:127.0.0.1,服务器: 本地主机,请求:“GET /install/ HTTP/1.1”,主机:“本地主机”

phpinfo 工作正常

这是我的配置:

1、/etc/nginx/nginx.conf

用户 www-data;

worker_processes 1;

pid /var/run/nginx.pid;

事件{ 工人连接768; # multi_accept on; }

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; }

2、/etc/nginx/sites-enabled/default

服务器{ 听 80; ## 监听 ipv4;此行是默认的和隐含的 #listen [::]:80 default_server ipv6only=on; ## 监听 ipv6

#root /usr/share/nginx/www;
root /var/www;
index index.html index.php;

# Make site accessible from http://localhost/
server_name localhost;
server_name_in_redirect off;

location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri $uri/ /index.html;
        try_files $uri $uri/ /index.php?$args;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
}

location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
}

# Rewrite for Fork CMS  

位置 ~ ^/(后端|安装|api(/\d.\d)?(/client)?).*.php$ { # backend/install/api 是现有的目录,但都应该通过前面的 try_files $uri $uri/ /index.php?$args; }

位置 ~ ^(.+.php)(.*)$ { 包括 fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }

# gzip  

gzip 开启;
gzip_disable "MSIE [1-6].(?!.*SV1)"; # 为不支持它的浏览器禁用 gzip 压缩(在这种情况下是 MS Internet Explorer 6 SV1 之前的版本)。 gzip_http_version 1.1; gzip_vary on; # 这会设置响应头 Vary: Accept-Encoding。 一些代理存在一个错误,即它们将压缩内容提供给 不支持的浏览器。通过设置 Vary: Accept-Encoding 标头,您指示代理存储压缩和 内容的未压缩版本。 gzip_comp_level 6; gzip_proxied 任何; gzip_types 文本/纯文本/css 应用程序/json 应用程序/x-javascript 文本/xml 应用程序/xml 应用程序/xml+rss 文本/javascript 应用程序/javascript 文本/x-js ; gzip_buffers 16 8k;

# client caching  location ~   \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$
{ expires 31d; add_header Pragma "public"; add_header Cache-Control
"public, must-revalidate, proxy-revalidate"; }

# End of Fork

【问题讨论】:

    标签: nginx debian


    【解决方案1】:

    我在 VPS 上的 nginx 上设置 WordPress,并且不断收到 403 禁止错误。权限设置正确,一切看起来都很好,但仍然得到 403。

    由于某种原因,每个人都建议使用此行:

    try_files $uri $uri/ /index.php?$args;
    

    当我按照上面 MAShady 的建议进行操作并删除了 $uri/ 时,它在我的服务器块中看起来像这样:

    try_files $uri /index.php?$args;
    

    ...令人惊讶的是,配置成功了!

    真的太棒了!

    非常感谢!

    【讨论】:

    【解决方案2】:

    您的问题是 http://localhost/install 通过 try_files 的第二条规则 $uri/ 因此它尝试将 install 作为文件夹访问,但您没有打开 autoindex,所以它因禁止错误而失败。

    try_files $uri $uri/ /index.php?$args;
    

    我建议删除$uri/ 部分。

    try_files $uri /index.php?$args;
    

    【讨论】:

    • 感谢@Mohammad-AbuShady,它有效。正如你所说,我没有打开autoindex,所以我尝试将autoindex on; 放在try_files $uri $uri/ /index.php?$args; 之前,但失败了。
    猜你喜欢
    • 2019-06-07
    • 2019-04-17
    • 2019-05-29
    • 1970-01-01
    • 2019-01-28
    • 2016-04-24
    • 2019-01-23
    • 2015-02-02
    相关资源
    最近更新 更多