Nginx配置https

上传文件到linux

java 复制代码
[root@zonghe01 nginx24]# pwd
/data/nginx24
[root@zonghe01 nginx24]# mkdir ssl
[root@zonghe01 ssl]# ll
total 8
-rw-r--r-- 1 root root 1675 Nov 15 22:19 xxx1.key
-rw-r--r-- 1 root root 3834 Nov 15 22:19 xxx2.pem

修改配置监听

java 复制代码
server {
        listen 8888 ssl;
        server_name xxx.gov.cn;
        underscores_in_headers on;
        ssl_certificate     /data/nginx24/ssl/xxx1.pem;
        ssl_certificate_key /data/nginx24/ssl/xxx2.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSV1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers on;

        #location / {
         #   root   html;
          #  index  index.html index.htm;
        #}
         location  /audit/ {
          alias /data/web/audit/lvfa_web/;
          index index.html /data/web/audit/lvfa_web/index.html;
        }
        location /minio/ {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                #proxy_set_header Host lft.xxx.com;
                proxy_set_header   Host $http_host;
                proxy_pass http://127.0.0.1:9000/;
        }

         location /api2/ {
                        proxy_pass http://http_res;
                        proxy_http_version 1.1;
                        proxy_set_header   Host $http_host;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
        }
         location /api/ {
                        proxy_pass http://http_res;
                        proxy_http_version 1.1;
                        proxy_set_header   Host $http_host;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
        }

nginx的ngx_stream_core_module模块,但是该模块在安装时不是默认构建的,需要在编译安装执行 ./configure时加上参数--with-http_ssl_module

java 复制代码
使用命令./nginx -V查看,如果在configure arguments后面没有出现--with-http_ssl_module则说明没有安装此模块
[root@test sbin]# cd /usr/local/nginx/sbin/
[root@test sbin]# ./nginx -Vnginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
configure arguments: --prefix=/usr/local/nginx
[root@test sbin]#

平滑安装https模块(如果之前没配置https模块)

java 复制代码
# 找到nginx源码目录,如此处nginx源码目录为:/home/nginx/nginx-1.24.0,即为编译命令执行目录
cd /data/nginx-1.24.0
# 执行编译命令
./configure --prefix=/data/nginx24 --with-http_ssl_module
# 执行make,此处一定不能使用make install命令,执行该命令会将原有nginx目录进行覆盖
make
# 关掉nginx
cd /data/nginx24/sbin/
./nginx -s stop# 
备份原有nginx二进制文件。
cp /data/nginx24/sbin/nginx /data/nginx24/sbin/nginx-no-https
# 复制新编译好的nginx二进制文件。从此处nginx源码目录为:/data/nginx-1.24.0。即为编译命令执行目录。
cp /data/nginx-1.24.0/objs/nginx /data/nginx24/sbin/nginx24
# 重新启动服务
cd /data/nginx24/sbin/
./nginx
# 可以通过./nginx -V命令查看以下模块是否安装成功
相关推荐
2301_8035545218 分钟前
https
网络协议·http·https
zhuyasen2 小时前
Go 实战:在 Gin 基础上上构建一个生产级的动态反向代理
nginx·go·gin
a123560mh4 小时前
国产信创操作系统银河麒麟常见软件适配(MongoDB、 Redis、Nginx、Tomcat)
linux·redis·nginx·mongodb·tomcat·kylin
百***35515 小时前
Linux(CentOS)安装 Nginx
linux·nginx·centos
micefind6 小时前
Nginx 反向代理完全指南:从安装到生产环境全流程
nginx
寂寞旅行9 小时前
Nginx配置WSS安全WebSocket代理
websocket·nginx·安全
心一信息11 小时前
http与https的详细介绍
网络协议·http·https
r***869811 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
暴躁哥14 小时前
linux ubuntu 下安装nginx
linux·nginx·ubuntu
r***998220 小时前
使用 Certbot 为 Nginx 自动配置 SSL 证书
运维·nginx·ssl