Debian 7下禁止使用nginx 403

yzuktlbb  于 5个月前  发布在  Nginx
关注(0)|答案(2)|浏览(56)

我遇到了一个403禁止错误在我的笔记本电脑与Debian 7
文件权限为775:chmod 775 -R /var/www
nginx错误日志显示:
2013/07/05 16:27:06 [error] 7351#0:12目录索引“/var/www/install/”被禁止,客户端:127.0.0.1,服务器:localhost,请求:“GET /install/ HTTP/1.1”,主机:“localhost”
phpinfo工作正常
我的配置:
/etc/nginx/nginx.conf
*
用户www-data;
worker_processes 1;
pid /var/run/nginx.pid;
事件{ worker_connections 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/*; }

字符串
/etc/nginx/sites-enabled/default**
server { listen 80; ## listen for ipv4;这一行是默认的,并暗示#listen [::]:80 default_server ipv6 only =on; ## listen for 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)(.*)$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }

# gzip


gzip on;
gzip_disable“MSIE [1-6]。(?!.* SV 1)"; #对不支持gzip压缩的浏览器禁用gzip压缩(在本例中,MS Internet Explorer版本6 SV 1之前). gzip_http_version 1.1; gzip_vary on; #这将设置响应头Vary:Accept-Encoding。某些代理有一个错误,因为它们将压缩内容提供给不支持它的浏览器。通过设置Vary:Accept-Encoding头,您指示代理存储内容的压缩和未压缩版本。gzip_comp_level 6; gzip_proxied any; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml+rss text/javascript application/javascript text/x-js ; gzip_buffers 16 8 k;

# 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

cwdobuhd

cwdobuhd1#

你的问题是http://localhost/install通过了try_files的第二条规则,也就是$uri/,所以它试图将install作为一个文件夹访问,但是你没有打开autoindex,所以它失败了,并出现了一个禁止错误。

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

字符串
我建议删除$uri/部分。

try_files $uri /index.php?$args;

8aqjt8rx

8aqjt8rx2#

我在VPS上设置WordPress在nginx上运行,并不断获得403禁止错误。如果设置正确,一切看起来都很好,但仍然不断获得403。
出于某种原因,每个人都建议使用这条线:

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

字符串
当我按照MAShady上面的建议删除$uri/时,它在我的服务器块中看起来像这样:

try_files $uri /index.php?$args;


.令人惊讶的是,配置工作!
真是厉害!
多谢了!

相关问题