nginx代理-http,配置缓存,以及默认跳转https网址

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

        }

    }

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值