阿里雲配置HTTPS

阿里雲配置HTTPSphp

2018-05-29 16:00:56 by SemiconductorKINGhtml

近申請域名配置了一下HTTPS協議,記錄一下配置過程。nginx

 

準備

  備案過的域名,一個SSL證書(免費的就行)。服務器

 

申請證書

  1. 登陸:阿里雲控制檯,產品與服務,證書服務,購買證書。
  2. 購買:證書類型選擇 免費型DV SSL,而後完成購買。
  3. 補全:在 個人證書 控制檯,找到購買的證書,在操做欄裏選擇 補全。填寫證書相關信息。
  4. 域名驗證:能夠選擇 DNS,若是域名用了阿里雲的 DNS 服務,再勾選一下 證書綁定的域名在 阿里雲的雲解析。
  5. 上傳:系統生成 CSR,點一下 建立。
  6. 提交審覈。

  若是一切正常,10 分鐘左右,申請的證書就會審覈經過。session

下載證書

   1.去你的域名管理頁,點擊SSL證書。app

  2.確認了已得到證書就去證書控制檯下載證書吧,解壓後有兩個文件。阿里雲

 

   3.不一樣的 Web 服務器地配置方法都不太同樣,下面用 NGINX 服務器做爲演示。spa

 

配置 NGINX 的 HTTPS

  1.服務器裏建立一個存儲證書的目錄(目錄不必定要和我同樣):code

sudo mkdir -p /etc/nginx/ssl/取個名字吧

 

 2.把申請並下載下來的證書,上傳到上面建立的目錄的下面。
  上傳我用的是scp固然你也能夠用其餘方式上傳到服務器:
scp -p 22 /Users/zxy/Downloads/1528845255923/1528845255923.key root@120.77.223.222:/etc/nginx/ssl/取個名字吧

scp -p 22 /Users/zxy/Downloads/1528845255923/1528845255923.pem root@120.77.223.222:/etc/nginx/ssl/取個名字吧

 

 3.而後你的你的證書的位置是:
/etc/nginx/ssl/取個名字吧/1528845255923.pem
/etc/nginx/ssl/取個名字吧/1528845255923.key

 

  4. 修改配置文件:server

 

server {
    #listen 80;將listen 80;修改爲監聽443端口
    listen 443;
    #server_name  localhost;
    server_name wechatapps.top;
    ssl          on;
    root /mnt/www/取個名字吧;
    index index.html;

    ssl_certificate   /etc/nginx/ssl/取個名字吧/1527005594992.pem;
    ssl_certificate_key  /etc/nginx/ssl/取個名字吧/1527005594992.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_prefer_server_ciphers on;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
#將http重定向到https,解決修改成https後http沒法訪問的問題 server { listen 80; server_name wechatapps.top; return 301 https://wechatapps.top; }

 修改後保存退出。 

 

  5.重啓服務

sudo systemctl reload nginx

 

 enjoy~

相關文章
相關標籤/搜索