nginx源码安装及配置https自签名
生活随笔
收集整理的這篇文章主要介紹了
nginx源码安装及配置https自签名
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
nginx源碼安裝
一般來說,用戶的服務(wù)器都是不練外網(wǎng)的。有的甚至可能沒有rpm源。所以個人還是喜歡從源碼進(jìn)行安裝。安裝參考以下的兩個鏈接:
官方從源碼安裝的介紹
官方源碼安裝包
雖然官方已經(jīng)有了安裝介紹,接下來還是自己安裝操作一次。
安裝基礎(chǔ)環(huán)境
安裝nginx之前要先安裝編譯環(huán)境gcc,g++,pcre, zlib,ssl 開發(fā)庫之類的需要提前裝好,安裝命令如下:
yum -y groupinstall 'Development Tools' yum -y install pcre pcre-devel yum -y install openssl openssl-devel上傳源碼,解壓預(yù)編譯源碼:
tar -zxvf nginx-1.23.0.tar.gz cd nginx-1.23.0 ./configure --prefix=/usr/local/nginx --with-http_ssl_module解釋一下,–prefix是安裝路徑,一般都是建議放到/usr/local/nginx目錄。–with-http_ssl_module是添加nginx的https模塊。
如果不經(jīng)過步驟1,有可能報下面的錯誤,像下面的錯誤就是沒有安裝PCRE:
編譯安裝
make && make install ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx #為了方便起見,創(chuàng)建軟連接前面的路徑是執(zhí)行路徑安裝完畢后啟動驗證一下服務(wù)和對應(yīng)的模塊:
[root@localhost bin]# nginx -V nginx version: nginx/1.23.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module如果連不上,請檢查是否關(guān)閉了防火墻
systemctl stop firewalld.serviceHTTPS自簽名
創(chuàng)建證書文件夾并生成key
cd ~ && makedir key && cd key openssl genrsa -des3 -out ssl.key 2048過程中隨便輸入1個密碼,要輸入兩次。
修改key中的密碼
mv ssl.key xxx.key openssl rsa -in xxx.key -out ssl.key #輸入上一步中的密碼 rm xxx.key生成crt證書并放到nginx目錄下
[root@localhost key]# openssl req -new -key ssl.key -out ssl.csr #過程中間一路回車 [root@localhost key]# openssl x509 -req -days 365 -in ssl.csr -signkey ssl.key -out ssl.crt Signature ok subject=/C=XX/L=Default City/O=Default Company Ltd Getting Private key [root@localhost key]# ll total 12 -rw-r--r--. 1 root root 1103 Jul 9 08:43 ssl.crt -rw-r--r--. 1 root root 952 Jul 9 08:34 ssl.csr -rw-r--r--. 1 root root 1679 Jul 9 08:31 ssl.key [root@localhost key]# [root@localhost key]# cp * /usr/local/nginx/conf/修改nginx配置文件
先備份歷史文件
找到最后面的配置文件,放開:
如同坑系列里面提的,一定要先驗證配置文件,然后再重啟
[root@localhost nginx]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful大功告成!!
總結(jié)
以上是生活随笔為你收集整理的nginx源码安装及配置https自签名的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用于实时实例分割的Deep Snake算
- 下一篇: VBA word 文件类型html,Wo