本地配置免费的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 就配置好了。有需要的小伙伴可以去试试,很简单。

相关推荐
LayZhangStrive3 小时前
后端通识 - 远程服务调用RPC
网络·网络协议·rpc·sentinel·openfeign·远程服务调用
华清远见成都中心5 小时前
FreeRTOS事件组(Event Group)的工作机制分析
服务器·网络·网络协议
tiantianuser6 小时前
NVME-oF IP 设计15 : 适于高速网络存储系统的IP设计1
网络协议·rdma·高速传输·cmac·roce v2
teak_on_my_way7 小时前
外网通过 Nginx 访问 Doris Stream Load:一次 HTTP 307 疑难排查与完整代理方案
运维·数据库·nginx·http
艺术留白8 小时前
MokaTest使用篇-HTTP接口
网络·网络协议·http
bbq粉刷匠8 小时前
HTTP 深度解析
网络·网络协议·http
tiantianuser9 小时前
NVME-oF IP 设计16 : 适于高速网络存储系统的IP设计2
网络协议·rdma·高速传输·roce v2·nvme of
2501_916007479 小时前
申请 iOS 推送证书并配置 APNs 群发推送教程
android·ios·小程序·https·uni-app·iphone·webview
FPGA小迷弟10 小时前
AXI4-Stream协议详解与Vivado自定义IP核封装实战
网络协议·tcp/ip·fpga开发·fpga·硬件开发
sudebao点com1 天前
一次“Google 能打开,FlexTV 打不开”的 DNS 故障排查:从 curl 超时到完整证据链
windows·macos·https·cdn·dns·nslookup·网络排错