nginx配置解决https不能访问的问题

一开始我只是简单的引入相关文件,并且开启监听443端口,结果对于非https的请求会出现这个错误:

400 The plain HTTP request was sent to HTTPS 

然后http里加入:

 map $scheme $fastcgi_https { ## Detect when HTTPS is used
         default off;
         https on;
  }

 

server里加

fastcgi_param HTTPS $fastcgi_https;

http {

     map $scheme $fastcgi_https { ## Detect when HTTPS is used
	     default off;
	     https on;
     }
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

   
    ssi on;

    server {
        listen       80;

        root    /data/static;
 	    server_name   localhost;

        listen 443 ssl;
  
        fastcgi_param HTTPS $fastcgi_https;

        ssl_certificate 213469990410554.pem;
        ssl_certificate_key 213469990410554.key;

        
	    charset utf-8;

        location = / {
            index index.html;
        }

        location / {
            index  index.html;
            proxy_pass http://127.0.0.1:9084;
        }
	
        location ~.*\.(js|css|png|gif|jpg|jpeg|bmp|html|rar|less|ico|ttf|woff|woff2|properties)?        $ {
            expires 4h;
        }
    }


}

这样就彻底解决了问题,不管是静态的还是动态的请求,不管是基于http的还是https的都没有问题了。

转载于:https://my.oschina.net/u/2275855/blog/703618

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值