日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx源码安装及配置https自签名

發(fā)布時間:2023/12/14 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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:

checking for PCRE library ... not found checking for PCRE library in /usr/local/ ... not found checking for PCRE library in /usr/include/pcre/ ... not found checking for PCRE library in /usr/pkg/ ... not found checking for PCRE library in /opt/local/ ... not found ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.

編譯安裝

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.service

HTTPS自簽名

創(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配置文件

先備份歷史文件
找到最后面的配置文件,放開:

server {listen 443 ssl;server_name localhost;ssl_certificate ssl.crt; #修改點ssl_certificate_key ssl.key; #修改點ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location / {root html;index index.html index.htm;}}

如同坑系列里面提的,一定要先驗證配置文件,然后再重啟

[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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。