欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx內(nèi)網(wǎng)環(huán)境開(kāi)啟https雙協(xié)議的實(shí)現(xiàn)

 更新時(shí)間:2025年02月21日 08:33:53   作者:Mr-Wanter  
本文主要介紹了Nginx內(nèi)網(wǎng)環(huán)境開(kāi)啟https雙協(xié)議,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

nginx開(kāi)啟https前提:

  • 服務(wù)器支持open-ssl
  • nginx 包含--with-http_ssl_module --with-stream --with-stream_ssl_preread_module模塊

一、open-ssl

1. 驗(yàn)證

openssl version

2. 安裝

 mkdir /usr/local/ssl
 cd /usr/local/ssl
 # 解壓
 tar -xf openssl-3.0.1.tar.gz
 # 設(shè)置SSL庫(kù)文件路徑
 ./config --prefix=/usr/local/ssl/
 make
 make install
vi /etc/ld.so.conf
# 最后一行添加/usr/local/ssl/ 路徑
sudo ldconfig 

常見(jiàn)報(bào)錯(cuò):openssl: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory系統(tǒng)版本和openssl版本不一致,具體哪里的日志記錄需要的版本忘記了

3.生成ssl證書

# 第一步:生成私鑰
mkdir /etc/ssl/certs/www.abc.com
cd /etc/ssl/certs/www.abc.com
openssl genrsa -des3 -out server.key 2048
# 輸入一個(gè)4位以上的密碼
# 確認(rèn)密碼
#第二步:生成CSR(證書簽名請(qǐng)求)
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=JiLin/L=ChangChun/O=commany/OU=commany/CN=www.abc.com"
#第三步:去除私鑰中的密碼
#在第1步創(chuàng)建私鑰的過(guò)程中,由于必須要指定一個(gè)密碼。而這個(gè)密碼會(huì)帶來(lái)一個(gè)副作用,那就是在每次啟動(dòng)Web服務(wù)器時(shí),都會(huì)要求輸入密碼
#這顯然非常不方便。要?jiǎng)h除私鑰中的密碼,操作如下:
openssl rsa -in server.key -out server.key
#第四步:生成自簽名SSL證書
# -days 證書有效期-天
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

一、nginx

1. 驗(yàn)證支持模塊

nginx -V

2. 安裝必要模塊

可以參考我之前的博客 Nginx 平滑升級(jí)

2.1 重新編譯nginx

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre --with-http_gzip_static_module --with-stream --with-stream_ssl_preread_module

生成nginx二進(jìn)制執(zhí)行文件到當(dāng)前目錄 /objs

 make

2.2 替換原文件

替換

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp /usr/local/nginx-1.13.3/objs/nginx /usr/local/nginx/sbin/

驗(yàn)證

[root@web nginx-1.21.5]# make upgrade
/usr/local/nginx/sbin/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
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

升級(jí)

#驗(yàn)證模塊是否加載成功
nginx -V

3. 配置https

下面是一段雙協(xié)議支持的配置代碼
請(qǐng)?jiān)试S我抄襲一下小左同學(xué)的代碼

stream {
    upstream http_protocol {
        # 8991端口是一個(gè)開(kāi)啟http的端口
        server 127.0.0.1:8991;
    }
    upstream https_protocol {
        # 10002端口是一個(gè)開(kāi)啟https的端口
        server 127.0.0.1:10002;
    }
    # 根據(jù)不同的協(xié)議走不同的upstream
    map $ssl_preread_protocol $upstream {
        default http_protocol;
        "TLSv1.0" https_protocol;
        "TLSv1.1" https_protocol;
        "TLSv1.2" https_protocol;
        "TLSv1.3" https_protocol;
    }
    server {
        listen 8990;
        ssl_preread on;
        proxy_pass $upstream;
    }
}
  server {
        listen 10002 ssl;
        server_name www.xxx.com;
        ssl_certificate /etc/ssl/certs/www.abc.com/server.crt;
        ssl_certificate_key /etc/ssl/certs/www.abc.com/server.key;
        #減少點(diǎn)擊劫持
        #add_header X-Frame-Options DENY;
        add_header X-Frame-Options AllowAll;
        #禁止服務(wù)器自動(dòng)解析資源類型
        add_header X-Content-Type-Options nosniff;
        #防XSS攻擊
        add_header X-Xss-Protection 1;
        #優(yōu)先采取服務(wù)器算法
        ssl_prefer_server_ciphers on;
        #協(xié)議
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;

        location / {
            proxy_pass http://127.0.0.1:8991/;
        }
    }

在這里插入圖片描述

總結(jié)

  • openssl: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory這個(gè)問(wèn)題是很大的難點(diǎn),排查好久才找到一個(gè)對(duì)應(yīng)版本安裝成功(我的是麒麟銀河V10,版本OpenSSL 1.1.1f),關(guān)鍵是怎么找到對(duì)應(yīng)版本的過(guò)程當(dāng)時(shí)沒(méi)有記錄,現(xiàn)在也想不起來(lái)了,??
  • open-ssl驗(yàn)證時(shí)本地發(fā)現(xiàn)有open-ssl,所以就跳過(guò)了第一步 結(jié)果nginx make報(bào)錯(cuò)
make -f objs/Makefile
make[1]: Entering directory '/opt/nginx-1.21.5'
cd /usr/local/ssl/ \
&& if [ -f Makefile ]; then make clean; fi \
&& ./config --prefix=/usr/local/ssl//.openssl no-shared no-threads  \
&& make \
&& make install_sw LIBDIR=lib
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [objs/Makefile:1447: /usr/local/ssl//.openssl/include/openssl/ssl.h] Error 127

OpenSSL源代碼未正確指定:在Nginx的配置過(guò)程中,你可能沒(méi)有正確指定OpenSSL的源代碼目錄。你需要確保–with-openssl選項(xiàng)指向的是OpenSSL的源代碼目錄,而不是安裝目錄。
上傳openssl-1.1.1f.tar.gz包(和驗(yàn)證時(shí)的版本一致即可)解壓后指定–with-openssl到解壓目錄--with-openssl=/opt/openssl-1.1.1f

./configure \
  --prefix=/usr/local/nginx \
  --user=nginx \
  --group=nginx \
  --with-pcre \
  --with-openssl=/opt/openssl-1.1.1f \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_sub_module \
  --with-http_dav_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_random_index_module \
  --with-http_secure_link_module \
  --with-http_stub_status_module \
  --with-http_auth_request_module \
  --with-http_image_filter_module \
  --with-mail \
  --with-threads \
  --with-mail_ssl_module \
  --with-stream_ssl_module \
  --with-stream --with-stream_ssl_preread_module \
 && make
  • 雙協(xié)議不支持獲取訪問(wèn)ip穿透
    更改為https或者h(yuǎn)ttp單協(xié)議可獲取到客戶端訪問(wèn)ip,如果代理中包含websocket需要把響應(yīng)代理放到和ssl配置的配置文件中
    關(guān)鍵配置:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

nginx.conf 示例

user root;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log;

events {
    worker_connections  1024;
}

http {
    # log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                   '$status $body_bytes_sent "$http_referer" '
    #                   '"$http_user_agent" "$http_x_forwarded_for"';
    log_format  main  '$year$month$day $hour:$minutes:$seconds ' '[$status] ' '【$http_x_forwarded_for $remote_addr $http_host】' '[$request_uri] ' ;

    access_log  /usr/local/nginx/logs/access.log  main;
	
    underscores_in_headers on;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include /etc/nginx/mime.types;
    client_max_body_size 10m;

    default_type        application/octet-stream;
    #default_type         text/html;


    #gzip
    gzip on;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain application/json application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml  font/woff;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    gzip_buffers 32 16k;
    gzip_http_version 1.0;

    include /usr/local/nginx/conf/conf.d/*.conf;

     server {
	    listen 8990 ssl;
		server_name www.bbcc.com;
        ssl_certificate /etc/ssl/certs/www.bbcc.com/server.crt;
        ssl_certificate_key /etc/ssl/certs/www.bbcc.com/server.key;
        #減少點(diǎn)擊劫持
        #add_header X-Frame-Options DENY;
        add_header X-Frame-Options AllowAll;
        #禁止服務(wù)器自動(dòng)解析資源類型
        add_header X-Content-Type-Options nosniff;
        #防XSS攻擊
        add_header X-Xss-Protection 1;
        #優(yōu)先采取服務(wù)器算法
        ssl_prefer_server_ciphers on;
        #協(xié)議
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;

        # 自定義時(shí)間變量
		if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
			set $year $1;
			set $month $2;
			set $day $3;
			set $hour $4;
			set $minutes $5;
			set $seconds $6;
		}

        location / {
            autoindex off;
        	proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://172.168.18.31:8990/;
        }
        
        location /gws {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://172.168.18.31:8990;
        }
    }
    
}

到此這篇關(guān)于Nginx內(nèi)網(wǎng)環(huán)境開(kāi)啟https雙協(xié)議的文章就介紹到這了,更多相關(guān)Nginx開(kāi)啟https雙協(xié)議內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • centos6.5下Nginx簡(jiǎn)單安裝教程

    centos6.5下Nginx簡(jiǎn)單安裝教程

    這篇文章主要為大家詳細(xì)介紹了centos6.5下Nginx的簡(jiǎn)單安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 基于nginx反向代理獲取用戶真實(shí)Ip地址詳解

    基于nginx反向代理獲取用戶真實(shí)Ip地址詳解

    我們?cè)L問(wèn)互聯(lián)網(wǎng)上的服務(wù)時(shí),大多數(shù)時(shí)客戶端并不是直接訪問(wèn)到服務(wù)端的,而是客戶端首先請(qǐng)求到反向代理,反向代理再轉(zhuǎn)發(fā)到服務(wù)端實(shí)現(xiàn)服務(wù)訪問(wèn),這篇文章主要給大家介紹了關(guān)于如何基于nginx反向代理獲取用戶真實(shí)Ip地址的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • nginx中一個(gè)請(qǐng)求的count計(jì)數(shù)跟蹤淺析

    nginx中一個(gè)請(qǐng)求的count計(jì)數(shù)跟蹤淺析

    這篇文章主要給大家介紹了關(guān)于nginx中一個(gè)請(qǐng)求的count計(jì)數(shù)跟蹤的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-01-01
  • 詳解Nginx location 匹配規(guī)則

    詳解Nginx location 匹配規(guī)則

    本篇文章主要介紹了Nginx location 匹配規(guī)則,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • 關(guān)于nginx+php5.3.8+eclipse3.7工作空間的配置方法

    關(guān)于nginx+php5.3.8+eclipse3.7工作空間的配置方法

    以前用eclipse3.6時(shí)設(shè)置php服務(wù)器時(shí)完全可以在base url欄填寫自己工作空間的目錄,然后修改nginx.conf加一個(gè)alias就行了
    2011-11-11
  • 使用Nginx作緩存服務(wù)器以及刪除其緩存文件的方法

    使用Nginx作緩存服務(wù)器以及刪除其緩存文件的方法

    這篇文章主要介紹了使用Nginx作緩存服務(wù)器以及刪除其緩存文件的方法,作cache時(shí)需要注意一下磁盤的IO瓶頸,需要的朋友可以參考下
    2015-11-11
  • nginx代理后端路徑獲取IP為127.0.0.1問(wèn)題

    nginx代理后端路徑獲取IP為127.0.0.1問(wèn)題

    文章討論了在使用Nginx作為反向代理時(shí),如何正確配置以避免在前端路徑A/api訪問(wèn)后端時(shí)丟失真實(shí)的IP地址,通過(guò)有效的Nginx配置,可以確保在前后端分離的場(chǎng)景中,客戶端通過(guò)前端路徑訪問(wèn)后端時(shí),后端能夠正確獲取客戶端的真實(shí)IP地址,示例配置展示了如何實(shí)現(xiàn)這一目標(biāo)
    2025-02-02
  • Nginx出現(xiàn)404 Not Found nginx/1.23.4的完美解決方案

    Nginx出現(xiàn)404 Not Found nginx/1.23.4的完美解決方案

    在Nginx配置過(guò)程中,404 Not Found錯(cuò)誤是一個(gè)常見(jiàn)問(wèn)題,本文將詳細(xì)解析Nginx 404 Not Found的原因及解決方案,確保您能夠輕松解決這一問(wèn)題,需要的小伙伴跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • nginx設(shè)置目錄白名單、ip白名單的實(shí)現(xiàn)方法

    nginx設(shè)置目錄白名單、ip白名單的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇nginx設(shè)置目錄白名單、ip白名單的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-08-08
  • nginx訪問(wèn)控制的實(shí)現(xiàn)示例

    nginx訪問(wèn)控制的實(shí)現(xiàn)示例

    這篇文章主要介紹了nginx訪問(wèn)控制的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論