nginx代理
一 配置缓存
nginx.conf配置
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;
server {
listen: 80;
server_name heiyan.com;
location / {
proxy_cache my_cache;
proxy_pass http: //127.0.0.1:8888,
proxy_set_header Host $host
}
}
配置请求头
1.'cache-Control': 's-maxage=20'(代理缓存)private(只使用浏览器缓存,不允许用代理缓存)
2.'cache-Control': 's-maxage=200'
'Vary': 'X-Test-Cache' // 指定一个头,只有请求时带的指定的头(X-Test-Cache)的值相等的情况下才使用缓存
二 配置https服务
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;
server {
listen 80;
server_name heiyan.com
ssl on;
ssl_certificate E:/software/nginx-1.6.3/key/heiyan/base/1685821_heiyan.com.pem;
ssl_certificate_key E:/software/nginx-1.6.3/key/heiyan/base/1685821_heiyan.com.key;
location / {
proxy_cache my_cache;
proxy_pass http: //127.0.0.1:8888,
proxy_set_header Host $host
}
}
三 http 跳https(访问http网址跳https的网址)
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name heiyan.com
return 302 https://server_name$request_uri;
}
server {
listen 80;
server_name heiyan.com;
location / {
proxy_pass http: //127.0.0.1:8888,
proxy_set_header Host $host
}
}
四 http2优势以及nginx的配置http2
http2: 信道复用 分帧传输(每一帧有上下的联系) server-push(服务端可以向客户端推送内容)
(只有https才支持http2)
server {
listen 443 http2;
server_name heiyan.com
http2_push_preload on;
ssl on;
ssl_certificate E:/software/nginx-1.6.3/key/heiyan/base/1685821_heiyan.com.pem;
ssl_certificate_key E:/software/nginx-1.6.3/key/heiyan/base/1685821_heiyan.com.key;
location / {
proxy_pass http: //127.0.0.1:8888,
proxy_set_header Host $host
}
}
1937

被折叠的 条评论
为什么被折叠?



