NGINX浏览器缓存不起作用-所有文件

我正在尝试配置Nginx以在浏览器上启用nginx缓存。我的配置文件如下

upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server
{
    listen               195.69.159.654:80;
    listen               195.69.159.654:443 ssl;
    listen               [::]:80 ipv6only=on;
    listen               [::]:443 ssl ipv6only=on;
    server_name www.domain.com *.domain.com ;
    root /home/admin/domains/domain.com/private_html;
    index index.php index.html index.htm;
    ssl_certificate /usr/local/directadmin/data/users/admin/domains/domain.com.cert.combined;
    ssl_certificate_key /usr/local/directadmin/data/users/admin/domains/domain.com.key;
    include /usr/local/directadmin/data/users/admin/nginx_php.conf;
    include /etc/nginx/webapps.ssl.conf;
    add_header strict-transport-security "max-age=31536000" always;
    return 301 domain.com$request_uri;

    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-XSS-Protection "1; mode=block";


ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_ecdh_curve secp384r1; # see here and here (pg. 485)
ssl_session_timeout 24h;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_buffer_size 4k; # I've since found 8k works best for this blog. (test!!) Default = 16k

}

server {
    server_name          domain.com *.domain.com;
    listen               195.69.159.654:80;
    listen               [::]:80;
    return 301 domain.com$request_uri;
}

server
{

    gzip on;
    gzip_comp_level    5;
    gzip_min_length    256;
    gzip_proxied       any;
    gzip_vary          on;
    gzip_types

    application/atom+xml
    application/javascript
    application/json
    application/ld+json
    application/manifest+json
    application/rss+xml
    application/vnd.geo+json
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/opentype
    image/bmp
    image/svg+xml
    image/x-icon
    text/cache-manifest
    text/css
    text/plain
    text/vcard
    text/vnd.rim.location.xloc
    text/vtt
    text/x-component
    text/x-cross-domain-policy;

    gzip_disable msie6;

listen               195.69.159.654:443 ssl;
listen               [::]:443 ssl;
server_name domain.com *.domain.com;
access_log /var/log/nginx/domains/domain.com.log;
access_log /var/log/nginx/domains/domain.com.bytes bytes;
error_log /var/log/nginx/domains/domain.com.error.log;
root /home/admin/domains/domain.com/private_html;
index index.php index.html index.htm;
ssl_certificate /usr/local/directadmin/data/users/admin/domains/domain.com.cert.combined;
ssl_certificate_key /usr/local/directadmin/data/users/admin/domains/domain.com.key;
include /usr/local/directadmin/data/users/admin/nginx_php.conf;
include /etc/nginx/webapps.ssl.conf;
add_header strict-transport-security "max-age=31536000" always;

add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";

proxy_connect_timeout       300;
proxy_send_timeout          300;
proxy_read_timeout          300;
send_timeout                300;

open_file_cache max=200000 inactive=20s; 
open_file_cache_valid 30s; 
open_file_cache_min_uses 2;
open_file_cache_errors on;


client_header_timeout  3m;
client_body_timeout    10;

client_header_buffer_size    1k;
large_client_header_buffers  4 4k;



output_buffers   1 32k;
postpone_output  1460;

sendfile         on;
tcp_nopush       on;
tcp_nodelay      on;

keepalive_timeout 2;
keepalive_requests 100000;
reset_timedout_connection  on;
server_tokens off;
client_body_buffer_size 128k;
client_max_body_size 10m;

 location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

location /nginx_status {
          stub_status on;
          access_log   off;
          deny all;
        }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
        location ~ .php$ {
            fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            include fastcgi_params;
        }

    location ~* \.(txt|log)$ {
        allow 192.168.0.0/16;
        deny all;
    }
    location ~* \.(eot|ttf|woff)$ {
        add_header access-control-allow-origin *;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
       return 403;
    }

    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    location ~* ^/.well-known/ {
        allow all;
   }

    location ~ (^|/)\. {
        return 403;
    }

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        include fastcgi_params;
        # Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_Proxy "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }

    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(jpeg|ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }
location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}
location ~ /\. {
    access_log off;
    log_not_found off; 
    deny all;
}

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
         return 444;
 }

location /images/ {
  valid_referers none blocked domain domain;
   if ($invalid_referer) {
     return   403;
   }
}



}

当我添加以下缓存配置时,服务器未缓存

NGINX浏览器缓存不起作用-所有文件

我已经在网上做了很多研究,但是不能解决这个问题。

有人可以帮助我,或者只是给我一些有关在Nginx中启用缓存的建议吗?谢谢!

ddoo88 回答:NGINX浏览器缓存不起作用-所有文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3115111.html

大家都在问