你好,我正在使用Nginx的Amazon Ec2。 我最近设置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 conf文件:
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; } } }
用ls -alh或stat命令检查文件/目录权限。 似乎可能是一个权限/所有权问题。
为了使文件可读,不仅文件需要读取权限,而且所有父目录也需要读取权限。 我的猜测是,而文件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-data或nginx )下运行的nginx对包含的目录没有读权限,因此无法访问jquery.js文件。 解决方法是更改“js”目录的权限,或将所有权更改为nginx用户。