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

你可能感兴趣的:(运维,后端)