nginx https的配置方法

文章目录

安装证书工具

curl 'http://pan.itshine.cn:5080/?explorer/share/fileOut\&shareID=64h6PiQQ\&path={shareItemLink%3A64h6PiQQ}%2F工具%2Fmkcert' > './mkcert'

chomd +x mkcert && cp mkcert /bin

安装根证书

mkcert -install

生成域名证书

mkcert 192.168.10.174

后面的IP地址必须是自己的IP地址或者是你的机器的nginx 一个虚拟主机server一个域名。

会有二个文件生产

  • 192.168.10.174.pem 包含公钥的证书,经过自签发了。
  • 192.168.10.174.key.pem 私钥

配置

复制代码
server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        server_name  _;
        root         /usr/share/nginx/html;
# 公钥证书,改成你自己的证书绝对路径
        ssl_certificate "/etc/nginx/ssl/192.168.10.42.pem";
# 私钥 ,改成自己绝对路径
        ssl_certificate_key "/etc/nginx/ssl/192.168.10.42-key.pem";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}

重新启动访问

https://your-ip/

转发 ssl的请求到http请求

复制代码
location /
{
# 改成你要代理到的http服务器,
    proxy_pass http://127.0.0.1:8087/;
    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_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
   # proxy_set_header Connection $connection_upgrade;
    proxy_set_header   X-Forwarded-Proto https;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_fileJKcauNzk 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_fileJKcauNzk 1;
  expires 1m;
    }
    if ( $static_fileJKcauNzk = 0 )
    {
        add_header Cache-Control no-cache;
    }
} 

将上述文字复制到 刚才虚拟主机当中。

相关推荐
众壹新能源科技12 小时前
逆变器半夜停机等备件48小时少发10万度电,备件安全库存怎么算
大数据·运维·安全
广州智造12 小时前
Radioss破坏模型FAILJOHNSON (Johnson-cook) 和 FAILTAB1
运维·数据库·自动化·仿真·建模·后处理·前处理
味悲12 小时前
Nginx笔记
linux·运维·笔记·nginx
电商全栈程序猿12 小时前
2026 开源商城系统选型指南:开发者实测对比Tigshop、ShopXO、CRMEB
java·运维·开源
时间售卖铺12 小时前
MySQL 库表设计:数据库范式详解
运维·数据库·mysql·云原生
Lucky_Turtle12 小时前
【Linux】ip命令,路由表相关配置
linux·运维·tcp/ip
dawnsky.liu12 小时前
在 RHEL 中使用 goose 实现主机运维
linux·运维·aiops
马立杰12 小时前
Docker Build 编译补丁版 PHP7.4 FPM 容器镜像教程(CVE-2026-109618 CVE-2026-109619)
运维·docker·容器·php
kkkkkkkkkk_Z13 小时前
新手自学嵌入式 | 学习日记: Linux驱动进阶 —— Platform总线与I2C子系统实战
linux·运维·学习
Android系统攻城狮13 小时前
Linux Gstreamer深度解析之gst_audio_aggregator_set_sink_caps调用流程与实战(九十一)
linux·运维·服务器·gstreamer音视频·音视频进阶