我正在尝试将图像和css / js的expires标头添加到我的Nginx配置中。但是一旦我添加它,它就会刹车,我无法正确获取网站。
这是我的nginx.con
worker_processes auto;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
types_hash_max_size 2048;
#BUFFER SIZE
client_body_buffer_size 128k;
client_max_body_size 10m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
output_buffers 1 32k;
postpone_output 1460;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /usr/local/nginx/logs/access.log;
error_log /usr/local/nginx/logs/error.log;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
### Proxy Settings
# proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=one:8m max_size=1000m inactive=600m;
# proxy_temp_path /usr/local/nginx/cache/tmp;
# proxy_cache_valid 404 1m;
# proxy_cache_valid 500 502 504 5m;
# proxy_cache_valid 200 302 1w;
# expires 1w;
# add_header Cache-Control "public";
# charset utf-8;
include /usr/local/nginx/conf/sites-enabled/*;
}
这里是服务器配置:
map $scheme $hsts_header {
http max-age=31536000;
}
server {
listen 80;
client_max_body_size 20M;
#root /usr/share/nginx/html;
#index index.html index.htm;
include includes/pageSpeedConfig;
include includes/redirects;
include includes/static-cache;
add_header Strict-Transport-Security $hsts_header;
add_header Strict-Transport-Security max-age=31536000 always;
location /probepage {
proxy_pass http://127.0.0.1:8080;
}
error_page 500 502 503 504 /502.html;
location = /502.html {
root /usr/local/nginx;
}
location /api {
proxy_pass http://127.0.0.1:8080;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /usr/local/nginx/proxy;
}
}
这里添加expires static-cache文件的配置包括:
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 365d;
}
我不包括https服务器,因为这是测试服务器。
你能帮忙吗?
非常感谢