制作私有ssl證書


1.編譯安裝nginx

安裝前准備:

service iptables stop

setenforce 0

yum -y install pcre-devel zlib-devel

useradd -M -s /sbin/nologin nginx

上傳nginx源碼包后

tar xf nginx-1.6.2.tar.gz -C /usr/src/

cd /usr/src/nginx-1.6.2/

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install   //編譯時加入--with-http_ssl_module參數

設置軟鏈接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

2.生成證書

進入創建證書和私鑰的目錄

cd /usr/local/nginx/conf/

創建服務器私鑰,回車后會讓你輸入一個口令:

openssl genrsa -des3 -out server.key 1024

創建簽名請求的證書(CSR):

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

回車后出現以下選項:(除了填寫域名,其他都可以直接回車跳過)

Country Name (2 letter code) [XX]:    ///國家

State or Province Name (full name) []:   ///省份

Locality Name (eg, city) [Default City]:   ///城市

Organization Name (eg, company) [Default Company Ltd]:   ///部門

Organizational Unit Name (eg, section) []:    ///組織或公司名稱

Common Name (eg, your name or your server's hostname) []:www.benet.com    ///域名

Email Address []:   ///郵箱

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

在加載SSL支持的Nginx並使用上述私鑰時除去必須的口令:

openssl rsa -in server.key -out server_nopwd.key

最后標記證書使用上述私鑰和CSR:

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

至此證書生成完畢

 

3.配置nging配置文件

vim nginx.conf

修改server段加入以下內容:

server {

        listen       443;

        server_name  localhost;

        ssl on;

        ssl_certificate  /usr/local/nginx/conf/server.crt;

        ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;

 

        charset utf-8;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

}

檢查nginx.conf語法是否有錯誤

nginx –t

啟動nginx

nginx

如果已經啟動,就使用killall nginx 命令先殺死nginx進程,然后再重新啟動

4.在客戶機上導入證書

首先把生成的證書傳到客戶機上

sz server.crt 192.168.1.104

在客戶機上操作:

控制面板 -> Internet選項 -> 內容 -> 發行者 -> 受信任的根證書頒發機構 -> 導入 -》選擇server.crt

然后在瀏覽器上輸入https://www.benet.com能夠正常訪問


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM