nginx配置ssl證書

配置背景:阿里雲域名的免費ssl證書html

 

1、參考如下官方配置文檔及視頻(官方教程很詳細)nginx

 

2、根據教程安裝完成,可是在重啓nginx時遇到如下的問題:安全

  nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:112session

  問題緣由:nginx安裝時沒有生成ssl模塊,須要在從新解壓安裝包,而後從新生成nginx,最後替換掉現有的nginx運行目錄中的對應的nginx文件就能夠了。dom

  問題解決:參考以下兩篇文章,很詳細ide

       https://yq.aliyun.com/articles/659755(官方解決辦法)網站

       http://www.javashuo.com/article/p-mlpckqzd-mt.html阿里雲

     

  解決問題,nginx啓動成功,但仍是沒法訪問:端口設置問題,https的必須是443(由於https的默認端口是443)加密

      注 :    當網址爲http://時,默認端口爲80spa

             當網址爲https://時,默認端口爲443

 

3、用戶打開http訪問時,自動跳轉至https訪問,官方配置文檔中也有詳細代碼介紹

  如下是,多個安全證書的配置文件: 配置多個安全證書,打開相應的http時,跳轉至對應的https 

  server {
        listen       80;
        server_name  www.ceshi.com;
        root /var/html/www;
        location / { 
                rewrite ^(.*)$  https://www.ceshi.com permanent;
        }
    }

    server {
        listen       80;
        server_name  www.ceshi2.com;
     #強制跳轉至https設置 return
301 https://www.ceshi2.com; } #我的網站 server { listen 443; server_name www.ceshi.com; ssl on; #將domain name.pem替換成您證書的文件名。 ssl_certificate cert/2339342_ceshi_com.pem; #將domain name.key替換成您證書的密鑰文件名。 ssl_certificate_key cert/2339342_ceshi_com.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 / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8083; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # HTTPS server 2  第二個安全證書的配置 server { listen 443 ssl; server_name www.ceshi2.com; ssl on; #將domain name.pem替換成您證書的文件名。 ssl_certificate cert/2339347_ceshi2_com.pem; #將domain name.key替換成您證書的密鑰文件名。 ssl_certificate_key cert/2339347_ceshi2_com.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 / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8083; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
相關文章
相關標籤/搜索