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

相关推荐
esmember10 小时前
电路研究9.2.6——合宙Air780EP中HTTP——HTTP GET 相关命令使用方法研究
网络·网络协议·http·at指令
weisian15112 小时前
消息队列篇--通信协议篇--STOMP(STOMP特点、格式及示例,WebSocket上使用STOMP,消息队列上使用STOMP等)
websocket·网络协议
追风赶月、15 小时前
【网络】传输层协议UDP
网络·网络协议·udp
霸王蟹16 小时前
http和https的区别?
网络·笔记·网络协议·学习·http·https
精通HelloWorld!16 小时前
使用HttpClient和HttpRequest发送HTTP请求
java·spring boot·网络协议·spring·http
泪不是Web妳而流17 小时前
BurpSuite抓包与HTTP基础
网络·经验分享·网络协议·安全·http·网络安全·学习方法
zhuyasen17 小时前
多维度详细比较 kratos、go-zero、goframe、sponge 框架
后端·http·微服务·rpc·golang
ybq1951334543119 小时前
javaEE-6.网络原理-http
网络·网络协议·http
我的青春不太冷20 小时前
《深入理解HTTP交互与数据监控:完整流程与优化实践》
网络·经验分享·科技·网络协议·学习·http·架构
A.sir啊1 天前
爬虫基础(五)爬虫基本原理
网络·爬虫·python·网络协议·http·pycharm