本地配置免费的https咋做?

大家好这里是tony4geek。

今天和公司的小伙伴对接项目,因为涉及到https的权限调用。所以在服务器本地localhost 要配置https用来测试 。现在把过程中遇到的问题记录下来。

• 因为是测试用所以生成https的证书用免费的就可以了。

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt

服务器上已经安装好docker,所以直接用docker 部署配置项目。

docker run -d -p 80:80 -p 443:443 --name my-nginx-scan

-v /home/path/html:/usr/share/nginx/html

-v /home/path/nginx.conf:/etc/nginx/nginx.conf

-v /home/path/server.crt:/etc/nginx/ssl/server.crt

-v /home/path/server.key:/etc/nginx/ssl/server.key

nginx

上面的代码中大概讲下几个参数的意思。v 后面第一个参数是服务器上,第二个是容器上的。

/home/path/html 这个路径是服务器上的路径。

/usr/share/nginx/html 这个路径是容器中的路径。

/home/path/nginx.conf: 这个是nginx 的配置参数。详细见下面的👇。

#user nginx;

worker_processes auto;

#error_log /var/log/nginx/error.log notice;

#pid /var/run/nginx.pid;

events {

worker_connections 1024;

}

http {

include /etc/nginx/mime.types;

default_type application/octet-stream;

复制代码
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

#include /etc/nginx/conf.d/*.conf;

server {
    listen       80;
    server_name  localhost;
    charset utf-8;

    location /{
        root /usr/share/nginx/html/;
       index  index.html index.htm;

        #expires 1d;
        #allow all;

    }
}

server {
    listen 443 ssl;
    server_name localhost;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        root /usr/share/nginx/html/;
        index  index.html index.htm;
    }
}

}

遇到问题如何解决?

docker exec -it my_container /bin/bash 可以进入到容器中查看服务器的资源是否拷贝过去。

至此 关于https 就配置好了。有需要的小伙伴可以去试试,很简单。

相关推荐
IpdataCloud4 小时前
批量查IP的API接口怎么选?免费API配额瓶颈与离线库本地批量方案实测
网络·网络协议·tcp/ip
GIoT80107 小时前
整段 C 段 IP 不能只看 Ping:一套实用的批量检测与分析思路
http
伤心的梧桐叶9 小时前
商品大图断点续传后打不开,先看是不是把完整响应又接了一遍
http·https
网络小江10 小时前
组网第33课:IP 地址与子网——CIDR、掩码、VLSM、网段规划与可用地址速算
网络协议·tcp/ip·子网掩码·vlsm·网络规划
山雀~11 小时前
WebSocket 断连之后:一次手机采集偶现卡死的排查与修复
网络·websocket·网络协议
码少女11 小时前
Linux——网络层-IP协议以及路由选择
linux·网络·网络协议·tcp/ip
dsadas12 小时前
ospf宣告网段的理解
网络协议
爱研究的小梁14 小时前
从无人车配送走向集群联动作业,通信如何扛住协同压力?
网络·网络协议·机器人·信息与通信
汤愈韬15 小时前
OSPF的虚链路
网络·网络协议
火22515 小时前
# C++ 微服务即时通讯系统(三):网关设计——HTTP 请求、Session 鉴权与 WebSocket 通知上一篇
c++·http·微服务