亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

前言

nginx開啟https前提:

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

一、open-ssl

1. 驗證

openssl version

2. 安裝

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

常見報錯: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
# 輸入一個4位以上的密碼
# 確認密碼
#第二步:生成CSR(證書簽名請求)
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)建私鑰的過程中,由于必須要指定一個密碼。而這個密碼會帶來一個副作用,那就是在每次啟動Web服務器時,都會要求輸入密碼
#這顯然非常不方便。要刪除私鑰中的密碼,操作如下:
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. 驗證支持模塊

nginx -V

2. 安裝必要模塊

可以參考我之前的博客 Nginx 平滑升級

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二進制執(zhí)行文件到當前目錄 /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/

驗證

[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`

升級

#驗證模塊是否加載成功
nginx -V

3. 配置https

下面是一段雙協(xié)議支持的配置代碼
請允許我抄襲一下小左同學的代碼

stream {
    upstream http_protocol {
        # 8991端口是一個開啟http的端口
        server 127.0.0.1:8991;
    }
    upstream https_protocol {
        # 10002端口是一個開啟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;
        #減少點擊劫持
        #add_header X-Frame-Options DENY;
        add_header X-Frame-Options AllowAll;
        #禁止服務器自動解析資源類型
        add_header X-Content-Type-Options nosniff;
        #防XSS攻擊
        add_header X-Xss-Protection 1;
        #優(yōu)先采取服務器算法
        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/;
        }
    }

在這里插入圖片描述

總結

  • openssl: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory這個問題是很大的難點,排查好久才找到一個對應版本安裝成功(我的是麒麟銀河V10,版本OpenSSL 1.1.1f),關鍵是怎么找到對應版本的過程當時沒有記錄,現(xiàn)在也想不起來了,??
  • open-ssl驗證時本地發(fā)現(xiàn)有open-ssl,所以就跳過了第一步 結果nginx make報錯
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的配置過程中,你可能沒有正確指定OpenSSL的源代碼目錄。你需要確保–with-openssl選項指向的是OpenSSL的源代碼目錄,而不是安裝目錄。
上傳openssl-1.1.1f.tar.gz包(和驗證時的版本一致即可)解壓后指定–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é)議不支持獲取訪問ip穿透
    更改為https或者http單協(xié)議可獲取到客戶端訪問ip,如果代理中包含websocket需要把響應代理放到和ssl配置的配置文件中
    關鍵配置:
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;
        #減少點擊劫持
        #add_header X-Frame-Options DENY;
        add_header X-Frame-Options AllowAll;
        #禁止服務器自動解析資源類型
        add_header X-Content-Type-Options nosniff;
        #防XSS攻擊
        add_header X-Xss-Protection 1;
        #優(yōu)先采取服務器算法
        ssl_prefer_server_ciphers on;
        #協(xié)議
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;

        # 自定義時間變量
		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;
        }
    }
    
}

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

相關文章

  • centos6.5下Nginx簡單安裝教程

    centos6.5下Nginx簡單安裝教程

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

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

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

    nginx中一個請求的count計數(shù)跟蹤淺析

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

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

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

    關于nginx+php5.3.8+eclipse3.7工作空間的配置方法

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

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

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

    nginx代理后端路徑獲取IP為127.0.0.1問題

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

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

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

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

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

    nginx訪問控制的實現(xiàn)示例

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

最新評論