Nginx配置Https

Posted 致林

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx配置Https相关的知识,希望对你有一定的参考价值。

1.申请证书:

https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qcloud

 

2.将证书导入服务器,xftp或者FileZilla都可以:

3.修改Nginx,我的Nginx位于/etc/nginx/ :

 

 

nginx自带ssl配置,删掉注释,修改证书位置就好了。

 

80端口配置:

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        #root         /usr/share/nginx/html;
     #注意添加下面这行代码,用于重定向 rewrite
^(.*) https://$server_name$1 permanent; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }

443端口设置:

server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
        ssl_certificate /etc/nginx/conf.d/1_www.bincoding.cn_bundle.crt;
        ssl_certificate_key /etc/nginx/conf.d/2_www.bincoding.cn.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

 

最后记得重启Nginx :  service nginx restart

 

参考: 

nginx配置https   https://www.v2ex.com/t/309382

常用服务器配置    https://mozilla.github.io/server-side-tls/ssl-config-generator/

以上是关于Nginx配置Https的主要内容,如果未能解决你的问题,请参考以下文章

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

Nginx配置文件详细介绍

Nginx 跨域

基于Nginx配置https证书

Nginx配置Https证书

为 Express 和 Nginx 配置 HTTPS