2

在阿里云服务器上使用Nginx部署https协议的网站

 6 months ago
source link: https://v3u.cn/a_id_80
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在阿里云服务器上使用Nginx部署https协议的网站

首页 - Mac & Linux/2019-05-21

    之前写过一篇文章是在阿里云服务器上用Apache切换https协议:将博客迁移阿里云并且切换成https解析的过程

    这一次,换成使用Nginx来部署,相比之下,比Apache的配置要简单一些

    如何申请SSL证书就按下不表了,非常简单,目前阿里云和腾讯云都免费提供一年的证书服务,区别就是腾讯云不需要域名在腾讯,而阿里云只有域名在阿里旗下才提供。

    申请域名证书成功后,下载压缩包,一定要选择Nginx的证书类型,解压后得到一个key文件一个pem文件,将这两个文件上传到服务器的root目录

    20190521104402_75730.png

    然后打开nginx配置文件

vim /etc/nginx/conf.d/default.conf

同时添加http和https的协议配置,需要注意的是,http需要阿里云安全协议暴露80端口,https需要阿里云安全协议暴露443端口

server {
    listen       80;
    server_name  m9u.cn;
    #这一步是http重定向到https,也可以不写
    rewrite ^(.*)$ https://${server_name}$1 permanent;
    access_log      /root/md_vue_access.log;
    error_log       /root/md_vue_error.log;


    client_max_body_size 75M;


    location / {

        root /root/fast_vue;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    error_log    /root/fast_vue/error.log    error;

}

server {

        listen 443;
        server_name m9u.cn;
        ssl on;
        ssl_certificate      /root/2238250_m9u.cn.pem;
        ssl_certificate_key  /root/2238250_m9u.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location / {

        root /root/fast_vue;
        index index.html;
        try_files $uri $uri/ /index.html;

        }

    }

重启nginx

systemctl restart nginx.service

使用https//访问

20190521104857_81205.png

没有问题,如果配置了重定向的话,那么访问http的内容将会自动301重定向到https,增加了安全等级


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK