博客
关于我
Nginx
阅读量:799 次
发布时间:2023-02-15

本文共 2633 字,大约阅读时间需要 8 分钟。

Nginx+SpringBoot配置SSL证书,实现https访问

Nginx+SpringBoot配置SSL证书,实现https访问

配置步骤

  • 获取域名并申请SSL证书

    首先需拥有域名,将其解析到服务器,申请与域名匹配的SSL证书。

  • 安装Nginx并开放443端口

    Nginx默认HTTP端口为80,HTTPS端口为443。安装完成后确保服务器开放443端口。

  • 通过SSH连接服务器并修改Nginx配置

    打开终端访问服务器,修改nginx.conf文件,完成HTTPS配置。

  • 重新启动Nginx完成配置

    修改完成后,输入命令sudo systemctl restart nginx使新配置生效。

  • Nginx配置示例

    # HTTPS配置server {    listen 443 ssl;    server_name www.haore.top;    keepalive_timeout 10m;    ssl_certificate /home/jar/www.pem;    ssl_certificate_key /home/jar/www.key;    ssl_session_timeout 24h;    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    ssl_prefer_server_ciphers on;    location / {        proxy_pass http://127.0.0.1:8288;        proxy_redirect 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_set_header X-Forwarded-Proto $scheme;    }}

    反向代理HTTP配置示例

    server {    listen 80;    server_name zcxcs.haore.top;    location / {        add_header 'Access-Control-Allow-Origin' $http_origin;        add_header 'Access-Control-Allow-Credentials' 'true';        add_header 'Access-Control-Allow-Methods' '*';        add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,U-TOKEN,E-TOKEN,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';        if ($request_method = 'OPTIONS') {            add_header 'Access-Control-Allow-Origin' $http_origin;            add_header 'Access-Control-Allow-Credentials' 'true';            add_header 'Access-Control-Allow-Methods' 'GET,POST,DELETE,PUT,OPTIONS';            add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,U-TOKEN,E-TOKEN,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';            add_header 'Access-Control-Max-Age' 1728000;            add_header 'Content-Type' 'text/plain; charset=utf-8';            add_header 'Content-Length' 0;            return 204;        }        proxy_pass http://localhost:8288;        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 X-Forwarded-Proto $scheme;        proxy_connect_timeout 5;    }}

    转载地址:http://macfk.baihongyu.com/

    你可能感兴趣的文章
    Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
    查看>>
    NMAP网络扫描工具的安装与使用
    查看>>
    NMF(非负矩阵分解)
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>