server { listen 80; server_name hocalhost; location / { root /usr/share/nginx/html; index index.html index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
图片
server { loction ~ .*.(jpg|png|gif)$ { gzip on; 启用压缩 gzip_http_version 1.1; http协议 gzip_comp_level 5; 压缩比例
expires 24h; 缓存24小时 gzip_types image/jpeg image/png image/jpg; 压缩内容类型 root /data/images; 目录 } }
HTML
server { loction ~ .*.(html|js|css)$ { gzip on; 启用压缩 gzip_min_length 1k; gzip_http_version 1.1; http协议 gzip_comp_level 9; 压缩比例 gzip_types text/css application/javascript root /data/html; 目录 } }
下载
server { location ~ ^/download { gzip_static on; 会找到gzip文件去下载 tcp_nopush on; root /data/download } }
跨域
server { location ~ .*.json$ { add_header Assess-Control-Allow-Origin http://localhose:8080; add_header Assess-Control-Allow-Metthods GET,POST; add_header Assess-Control-Allow-Headers Content-Type; add_header Assess-Control-Allow-Credentials true; gzip on; gzip_http_vesrsion 1.1; gzip_comp_level 5; root /data/file; } }