久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Nginx接收Http協(xié)議請求轉(zhuǎn)發(fā)使用Https協(xié)議的問題

瀏覽:5日期:2023-08-07 20:15:49
目錄緣起第一次配置Nginx重新編譯Nginx重啟Nginx緣起

公司使用阿里的apigateway,規(guī)定不太友好,同是SIT環(huán)境,A系統(tǒng)的SIT1環(huán)境居然不能調(diào)用B系統(tǒng)的SIT2環(huán)境的接口。因為各個系統(tǒng)之間部署的SIT環(huán)境數(shù)量不同A系統(tǒng)可能只有1套,B系統(tǒng)可能有8套,這樣的話,可能會隨時切換調(diào)用B系統(tǒng)的環(huán)境,管理員不允許,于是想著用Nginx做下轉(zhuǎn)發(fā)。因為A系統(tǒng)調(diào)用B系統(tǒng)是內(nèi)部調(diào)用,不計劃使用HTTPS,因為還要去申請證書,但是B系統(tǒng)調(diào)用入口必須使用HTTPS,這樣就要求Nginx可以接收HTTP協(xié)議的請求,轉(zhuǎn)發(fā)出去的協(xié)議是HTTPS。

第一次配置Nginxserver {listen 10000;server_name 192.168.1.2;error_page 500 502 503 504 /50x.html;location = /50x.html { root html;}location / { proxy_pass https://aaa.bbb.com:9000;} }

以為這樣就可以直接轉(zhuǎn)發(fā)了,但是執(zhí)行nginx -t直接報錯:

nginx: [emerg] https protocol requires SSL support in /data/nginx/conf/nginx.conf:224nginx: configuration file /data/nginx/conf/nginx.conf test failed

224行就是我上面的proxy_pass https://aaa.bbb.com:9000;這一行搜了一下說是nginx當(dāng)時編譯的時候沒有http_ssl_module模塊,使用nginx -V查看一下當(dāng)時編譯的參數(shù):

nginx version: nginx/1.21.5built by gcc 4.8.5 (SUSE Linux) configure arguments: --prefix=/data/nginx --with-pcre=/data/software/pcre-8.21 --with-zlib=/data/software/zlib-1.2.11 --with-openssl=/etc/ssl

果然沒有http_ssl_module模塊,于是決定重新編譯一下nginx。

重新編譯Nginx

注意:我的輸出是/data/nginx,和當(dāng)前正在跑的Nginx是同一個目錄,先使用nginx -s stop停止nginx,然后備份conf/nginx.conf文件,防止被覆蓋。

先安裝依賴:pcre-8.21,zlib-1.2.11,openssl-1.0.2t我都是下載的源碼,然后編譯并安裝的

# pcre-8.21 使用以下命令cd pcre-8.21 && ./configure && make && make install# zlib-1.2.11 使用以下命令cd zlib-1.2.11 && ./configure && make && make install# openssl-1.0.2t 比較特殊 使用cd openssl-1.0.2t && ./config && make && make install

進(jìn)入Nginx源碼目錄然后使用以下命令configure:

./configure --prefix=/data/nginx --with-pcre=/data/software/pcre-8.21 --with-zlib=/data/software/zlib-1.2.11 --with-openssl=/data/software/openssl-1.0.2t --with-http_ssl_module

然后執(zhí)行編譯和安裝:

make && make install重啟Nginx

編譯完成后發(fā)現(xiàn)之前的Nginx二進(jìn)制文件變成了nginx.old,新的Nginx文件叫nginx,給這個nginx二進(jìn)制加執(zhí)行權(quán)限,然后執(zhí)行

nginx -t

此時不再報錯,提示成功:

nginx: the configuration file /data/nginx/conf/nginx.conf syntax is oknginx: configuration file /data/nginx/conf/nginx.conf test is successful

然后查看conf/nginx.conf,發(fā)現(xiàn)沒有被覆蓋,可以直接啟動Nginx了:

nginx -c /data/nginx/conf/nginx.conf

啟動完成后用ps命令查看以下進(jìn)程果然在。然后使用postman測試,發(fā)現(xiàn)可以正確轉(zhuǎn)發(fā),大功告成。

到此這篇關(guān)于Nginx接收Http協(xié)議請求轉(zhuǎn)發(fā)使用Https協(xié)議的文章就介紹到這了,更多相關(guān)Nginx接收Http協(xié)議請求內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Nginx
主站蜘蛛池模板: 大连市| 舟山市| 巴林右旗| 乐昌市| 黑龙江省| 甘孜县| 调兵山市| 广宗县| 杭州市| 长海县| 富锦市| 广河县| 岐山县| 上犹县| 霸州市| 凌海市| 松滋市| 大同县| 准格尔旗| 梁山县| 金阳县| 大洼县| 襄汾县| 沙洋县| 英吉沙县| 淮北市| 临沭县| 武夷山市| 宝兴县| 沙坪坝区| 灵石县| 阿鲁科尔沁旗| 什邡市| 宁远县| 蓬安县| 昌都县| 南丹县| 错那县| 东安县| 南涧| 开远市|