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

相关推荐
GZ_TOGOGO3 小时前
【2024最新】华为HCIE认证考试流程
大数据·人工智能·网络协议·网络安全·华为
三金121384 小时前
SpringIoC容器的初识
网络·网络协议·rpc
SizeTheMoment6 小时前
初识HTTP协议
网络·网络协议·http
程序员-珍9 小时前
虚拟机ip突然看不了了
linux·网络·网络协议·tcp/ip·centos
魏大橙11 小时前
linux RCE本地/公网测试
网络·网络协议·udp
l1x1n011 小时前
No.3 笔记 | Web安全基础:Web1.0 - 3.0 发展史
前端·http·html
鄃鳕12 小时前
HTTP【网络】
网络·网络协议·http
读心悦13 小时前
如何在 Axios 中封装事件中心EventEmitter
javascript·http
CXDNW14 小时前
【网络篇】计算机网络——应用层详述(笔记)
服务器·笔记·计算机网络·http·web·cdn·dns
秋夫人16 小时前
http cache-control
网络·网络协议·http