1. 程式人生 > >Ubuntu 16.04配置SSL免費證書

Ubuntu 16.04配置SSL免費證書

pre 令行 try 開啟 apach init href detail 一個

主要參考地址為:https://blog.csdn.net/setoy/article/details/78441613

本篇主要以Apache這個web服務器來講解,所以前提必須要安裝好apache。

關於安裝Apache,對於Ubuntu來說,一行命令行就能搞定。

sudo apt-get install apache2

當然了,如果有對lnmp或者lanmp環境搭建感興趣的可以參考我的這篇博文:Ubuntu16.04之開發環境構建

雖說該文排版有待改善,但是內容還是很實用的。

1.開啟SSL模塊

a2enmod ssl

上面的命令相當於下面兩條命令:

sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled

如果沒有a2enmod指令,也可直接在apache2.conf中設置SSL模塊加載:

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

不過註意,一般都用不到這個,因為安裝apache2時,自帶有a2enmod指令。

2.創建第三方CA機構簽署證書,並向它提交“生成證書的請求文件”(文件後綴通常為.csr)

openssl genrsa -des3 -out server.key 1024

-des3選項能對私鑰進行加密,采用此選項會在後續的設置中提示你輸入密碼(只是加密私鑰,https訪問時不需要這個密碼)

這樣會在當前目錄下生成server.key私鑰文件

3.生成請求文件csr

openssl req -new -key server.key -out server.csr

執行這條命令後,會在小黑窗裏顯示如下需要填寫的內容:

Country Name
Province Name
Common Name
Email

其中Common Name最好用域名,否則https訪問時會出現證書不一致的情況

4.自己簽發證書

openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

3650表示證書有效期10年

5.修改apache配置文件

ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
vim /etc/apache2/sites-enabled/default-ssl.conf

在DocumentRoot中加入內容:

SSLEngine On  
SSLOptions +StrictRequire  
SSLCertificateFile /etc/ssl/certs/server.crt  
SSLCertificateKeyFile /etc/ssl/private/server.key  

6.重啟Apache即可

/etc/init.d/apache2 restart

完成上面的不能代表,就可以直接使用。上面的步驟,只是一個搭建,可以讓你看到界面上的簡單效果。

簡而言之的說,中看不中用。但是總的來說,它仍然是有益的。希望能夠給廣大朋友帶來幫助。

Ubuntu 16.04配置SSL免費證書