禁止使用Nginx 1.8缓存403

时间:2016-01-06 09:58:48

标签: nginx

我只想缓存我的网站的网址/。但是当我请求url时,得到403错误,(其他网址没问题)。错误日志:

2016/01/06 17:25:04 [error] 26263#0: *1 directory index of "/home/app/path/" is forbidden, client: 223.85.143.126, server: domain.com, request: "GET / HTTP/1.1", host: "www.domain.com", referrer: "http://www.domain.com/accounts/"

我在nginx.conf中尝试chmod 777 -R /home/app/path/chmod 777 -R /home/app/path/nginx_cache或将user nginx;更改为user root;,一切都行不通。

这是信息。

启用网站的conf:

proxy_cache_path /home/app/path/nginx_cache levels=1:2 keys_zone=my_cache:1m max_size=50m inactive=60m use_temp_path=off;

server {
    listen 80;
    server_name domain.com www.domain.com;
    index index.html index.htm;
    root /home/app/path;
    charset utf-8;
    client_max_body_size 5M;  
    if ($host !~* ^(domain.com|www.domain.com)$){
        return 444;
    }
    location /media  {
        alias /home/app/path/media;
    }
    location /static {
        alias /home/app/path/static;
    }
    location / {
        uwsgi_pass  127.0.0.1:3032; 
        include     /home/app/path/uwsgi_params;
    }
    location = / {
        proxy_cache my_cache;
        proxy_cache_valid 15s;
    }
}

nginx.conf:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  768;
}

http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 30;
    types_hash_max_size 2048;
    reset_timedout_connection on;
    client_body_timeout 10;

    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;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

1 个答案:

答案 0 :(得分:1)

位置不继承规则,因此没有UWSGI传递,nginx尝试显示目录​​索引并失败。应该是这样的:

location = / {
    uwsgi_pass  127.0.0.1:3032; 
    include     /home/app/path/uwsgi_params;
    proxy_cache my_cache;
    proxy_cache_valid 15s;
}