NGINX не кэширует контент

Надеюсь, кто-нибудь сможет пролить сюда немного света, раз уж я застрял в темноте :-P

В основном, я пытаюсь сделать содержимое кэша NGINX обратного прокси. Обратное проксирование работает нормально, но часть кеширования ... нет. Я' я следовал многим руководствам и различным подходам, но все результаты в моей папке кэша пуста и в каждом

curl -X GET -I ресурсе , возвращающем X-Proxy-Cache: MISS

My Как я уже сказал, установка очень проста, у меня есть один внутренний сервер, на котором работают Apache и Tomcat, и внешний интерфейс, на котором выполняется обратное проксирование всех запросов NGINX.

Я просто опубликую информацию для одного конкретного (и самого простого) виртуального хоста nginx , который обслуживает установку Owncloud.

cat / etc / redhat-release

CentOS Linux, выпуск 7.2.1511 (Core)

NGINX -V

nginx version: nginx/1.6.3
built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    ## BEGIN PROXY PARAMS ##

    proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=one:10m inactive=24h  max_size=1g;

    # END PROXY PARAMS ##

    ## BEGIN SECURITY ##

    # Prevent attackers to find out which nginx version is running.
    server_tokens off;

    ## END SECURITY ##

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        #root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        # include /etc/nginx/default.d/*.conf;

        location / {
            return 403;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

01-owncloud.conf

server {
    listen      80;
    server_name cloud.mydomain.com;
    access_log  /var/log/nginx/01-owncloud_access.log;
    error_log   /var/log/nginx/01-owncloud_error.log error;

    ## BEGIN SECURITY ##

    # Block nasty robots
    if ($http_user_agent ~ (msnbot|Purebot|Baiduspider|Lipperhey|Mail.Ru|scrapbot) ) {
        return 403;
    }

    # Deny referal spam
    if ( $http_referer ~* (jewelry|viagra|nude|girl|nudit|casino|poker|porn|sex|teen|babes) ) {
        return 403;
    }

    ## END SECURITY ##

    location / {
        #proxy_cache_bypass  $http_cache_control;
        #add_header X-Proxy-Cache $upstream_cache_status;
        proxy_redirect    off;
        proxy_set_header  Host               $host;
        proxy_set_header  X-Forwarded-Server $host;
        proxy_set_header  X-Real-IP          $remote_addr;
        proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto  http;
        proxy_pass      http://192.168.1.42:80/;
        proxy_cache            one;
        proxy_cache_valid      200  1d;
        proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
    }
}

Любая помощь приветствуется.

Спасибо, что прочитали этот пост!

Удачного дня!

1
задан 18 December 2015 в 18:06
1 ответ

Старый пост, .. но я хотел его обновить-

В конце концов, это был SELinux, который не позволял процессу nginx записывать в / etc / nginx / cache. Быстрый просмотр / var / log / messages показал это, и с установленным сервером setroubleshoot-server он дал мне правильные команды для выполнения для разрешения этой записи.

0
ответ дан 4 December 2019 в 06:44

Теги

Похожие вопросы