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

相关推荐
捧 花8 小时前
HTTP的补充
http·cookie·session·http缓存·工作流程
头发还没掉光光9 小时前
HTTP协议从基础到实战全解析
linux·服务器·网络·c++·网络协议·http
数通工程师10 小时前
企业级硬件防火墙基础配置实战:从初始化到规则上线全流程
运维·网络·网络协议·tcp/ip·华为
budingxiaomoli12 小时前
HTTP协议
网络·网络协议·http
2401_8735878213 小时前
Linux——应用层协议定制
linux·运维·网络协议
你这个代码我看不懂13 小时前
Spring Boot拦截Http请求设置请求头
spring boot·后端·http
郝学胜-神的一滴17 小时前
深入理解TCP协议:数据格式与核心机制解析
linux·服务器·网络·c++·网络协议·tcp/ip
Serendipity-Solitude18 小时前
TCP/IP协议栈深度解析技术文章大纲
网络·网络协议·tcp/ip
小π军18 小时前
TCP协议:拥塞控制与流量控制的区别
网络·网络协议·tcp/ip
那就回到过去18 小时前
IP组播技术(2)
网络·网络协议·tcp/ip·智能路由器·ensp