AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 616788
Accepted
Maca
Maca
Asked: 2014-07-31 19:33:20 +0800 CST2014-07-31 19:33:20 +0800 CST 2014-07-31 19:33:20 +0800 CST

Nginx:403 Forbidden on some files extension

  • 772

您好,我正在将 Amazon Ec2 与 Nginx 一起使用。我最近设置了 nginx,例如当我访问 blog.com/index.php 时,它会正确显示在浏览器中,但是当我访问 JPEG、PNG、JS 等其他文件扩展名时,文件变为 403。

这是错误日志。

[error] 5637#0: *132 open() "/var/www/html/js/jquery.js" failed (13: Permission denied), client: 10.000.00.00, server: blog.com, request: "GET /js/jquery.min.js HTTP/1.1", host: "blog.com"

js文件的权限统计(403 Forbiddon)

-rw-r--r-- 1 ec2-user ec2-user 93636 /var/www/html/js/jquery.js

index.php 文件的权限统计信息

-rw-r--r-- 1 ec2-user ec2-user 1281  /var/www/html/index.php

我的 Nginx 配置文件:

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  8096;
    multi_accept on;
    use epoll;
}


http {
    charset UTF-8;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  off;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay        on;
    server_tokens     off;

    keepalive_timeout  10;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;
    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;

    gzip  on;
    gzip_static on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm index.php;

    server {
        listen       80;
        server_name  localhost;
        root         /var/www/html;
        location / {
        }
        error_page  404              /404.html;
        location = /40x.html {
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
        location ~* \.php$ {
        location ~* \.php$ {
          fastcgi_index   index.php;
          fastcgi_pass  unix:/var/run/php-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

    }


    server {
    listen 80;
    server_name blog.com;

      location / {
          root    /var/www/html;
          index   index.html index.htm index.php;
      }

      location ~* \.php$ {
      ssi on;
      root /var/www/html;
      fastcgi_param HTTP_USER_AGENT  $http_user_agent;
      fastcgi_index   index.php;
      fastcgi_pass   unix:/var/run/php-fpm.sock;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME    /var/www/html$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

      }

    }

}
nginx
  • 2 2 个回答
  • 8599 Views

2 个回答

  • Voted
  1. Best Answer
    TBI Infotech
    2014-08-01T00:01:26+08:002014-08-01T00:01:26+08:00

    ls -alh使用orstat命令检查文件/目录权限。似乎可能是权限/所有权问题。

    • 5
  2. Jaap Joris Vens
    2014-07-31T23:54:21+08:002014-07-31T23:54:21+08:00

    为了使文件可读,不仅文件需要读取权限,而且所有父目录都需要读取权限。我的猜测是文件 jquery.js 具有正确的权限:

    -rw-r--r-- 1 ec2-user ec2-user 93636 /var/www/html/js/jquery.js
    

    ,目录 js 没有:

    -rwxr-x--- 1 ec2-user ec2-user 93636 /var/www/html/js
    

    在这种情况下,在另一个用户(例如www-dataor nginx)下运行的 nginx 对包含目录没有读取权限,因此无法访问文件 jquery.js。解决方案是要么更改“js”目录的权限,要么将所有权更改为 nginx 用户。

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve