Nginx+Tomcat反向 Proxy利用certbot實現https

來源:互聯網
上載者:User

標籤:save   chain   rtb   form   lease   server   etc   webroot   認證   

一、利用Let‘s Encrypt 免費產生HTTPS認證

1、下載安裝certbot(Let‘s Encrypt )

2、利用certbot產生認證

3、配置nginx的https認證

安裝cerbot
[[email protected] ~]# wget https://dl.eff.org/certbot-auto[[email protected] ~]# chmod a+x certbot-auto[[email protected] ~]#./certbot-auto 

 

利用certbot產生認證
[[email protected] certbot]# ./certbot-auto certonly --email  [email protected] --agree-tos --webroot -w  /alidata1/www/timecash22/api3  -d  xxxx.zjm.cn/root/.local/share/letsencrypt/lib/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6  DeprecationWarningSaving debug log to /var/log/letsencrypt/letsencrypt.logObtaining a new certificatePerforming the following challenges:http-01 challenge for xxx.zjm.cnUsing the webroot path /alidata1/www/timecash22/api3 for all unmatched domains.Waiting for verification...Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at   /etc/letsencrypt/live/xxx.zjm.cn/fullchain.pem. Your   cert will expire on 2017-09-06. To obtain a new or tweaked version   of this certificate in the future, simply run certbot-auto again.   To non-interactively renew *all* of your certificates, run   "certbot-auto renew" - If you like Certbot, please consider supporting our work by:    Donating to ISRG / Let‘s Encrypt:   https://letsencrypt.org/donate   Donating to EFF:                    https://eff.org/donate-le-w:指定網域名稱的根目錄-d:指定網域名稱Note:認證已經產生到了/etc/letsencrypy/live/xxx.zjm.cn下

Nginx配置https認證

#http訪問        server {           listen       80;        server_name  www.xxx.cn;        return     301  https://$server_name$request_uri;    }#https訪問      server {        listen 443 ssl;        server_name www.xxx.cn;        ssl_certificate /etc/letsencrypt/live/www.xxx.cn/fullchain.pem;       ssl_certificate_key/etc/letsencrypt/live/www.xxx.cn/privkey.pem;     ssl_trusted_certificate/etc/letsencrypt/live/www.xxx.cn/chain.pem;     ssl_dhparam /etc/nginx/ssl/dhparam.pem;           location  / {                        proxy_pass http://www.xxx.cn/;                      }           }ssl_certificate和ssl_certificate_key分別對應fullchain.pem,privkey.pemssl_dhparam通過以下命令產生$ mkdir /etc/nginx/ssl$ openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

 

 

自動更新https認證

由於這個免費的認證只有90天的使用時間,所以遇到定時更新以下認證,這裡是利用certbot每隔一段時間自動更新認證

手動執行更新

./certbot-auto  renew --dry-run

 

結合crontab每隔一段時間自動更新認證

30 2 * * 1 ./certbot-auto  renew  >> /var/log/le-renew.log

PS:

        1、產生認證的時候切記-w參數後邊的網站目錄要寫對,不然會報錯

   2、只需配nginx支援https就好,tomcat不用配置

         3、前端代碼和後端介面必須支援https

Nginx+Tomcat反向 Proxy利用certbot實現https

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.