我试图在我的网站上分享我的一些个人媒体,但当我尝试访问它时(www.example.com/media),我收到了一个403 Forbidden错误。 但是,当我提供文件的完整path,例如www.example.com/media/2001/golden_retriever.jpg我可以看到实际的图片。
我已启用autoindex on; 在/etc/nginx/sites-available/example.com这样的:
location /media { allow all; autoindex on; }
我重新启动service nginx restart ,我得到了同样的错误。 我试着把autoindex on; 在location / { }和实际的server { }块内无济于事。 基本上,改变后重新启动nginx服务器什么都不会发生。
整个站点可用的configuration:
server { listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /usr/share/nginx/www/example; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name example.com www.example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # 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; deny all; } location /media { allow all; autoindex on; } # Only for nginx-naxsi : process denied requests #location /RequestDenied { # For example, return an error code #return 418; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #error_page 500 502 503 504 /50x.html; #location = /50x.html { # root /usr/share/nginx/www; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass unix:/var/run/php5-fpm.sock; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
请注意,这个configuration有一个符号链接,对站点启用完全相同的名称。
这似乎是错误的符号链接。 创build符号链接时,请使用完整path,而不是像这样的相对path :
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enable/example.com
您确定/usr/share/nginx/www/example/media具有权限设置,以便Web服务器进程可以访问该目录吗?
如果您通过自己的用户帐户创build了该目录,则需要确保其他权限组具有对该目录的读取和执行权限。
chmod a+rx /usr/share/nginx/www/example/media
读取/执行权限添加到目录。
此外,目录中的文件应具有另一个组的读取权限:
chmod a+r /usr/share/nginx/www/example/media/*