https和http共存的nginx配置

原來有一個域名是http://www.art-china.club

但現在都流行加SSL證書,實現https的訪問,今天實驗了下非常的簡單,配置如下:
現在https://www.art-china.club 也可以正常訪問了

將域名的證書文件1_www.domain.com_bundle.crt 、私鑰文件2_www.domain.com.key保存到同一個目錄,例如/usr/local/nginx/conf目錄下。
更新Nginx根目錄下 conf/nginx.conf 文件如下:

server {
listen 80;
listen 443 ssl;
server_name test.xx.com;
index index.html index.htm index.php;
root /usr/local/default;

          ssl_certificate 1_www.domain.com_bundle.crt;
    ssl_certificate_key 2_www.domain.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照這個協議配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照這個套件配置
    ssl_prefer_server_ciphers on;

    location ~ .*\.(php|php5)?$
    {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
            #expires 30d;
    }
    location ~ .*\.(js|css)?$
    {
            #expires 1h;
    }

    access_log  logs/test.access.log;

}

配置完成後,先用bin/nginx –t來測試下配置是否有誤,正確無誤的話,重啓nginx。就可以使用 https 來訪問了。

證書申請請到你的域名服務商出申請阿里雲和騰訊都有免費的證書。
阿里雲:https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=2uqqq683
騰訊雲:https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=0138fdf13409ab6836352f2816a0f8f8&from=console

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章