Globe

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 搭建教程
  3. 正文

A-acme证书申请以及配置HTTPS

2023年10月10日 34点热度 0人点赞 0条评论

1.A-acme证书申请:
停用nginx,防止80端口被占用:
systemctl stop nginx

注意:用warp的童鞋记着先关闭warp,申请完证书可以继续打开使用

安装一些需要的软件包:
apt-get install -y openssl cron socat curl unzip vim

使用自己的邮箱申请证书:(用别人的会发邮件到别人邮箱,泄露自己信息)
curl https://get.acme.sh | sh -s email=你的邮箱
source ~/.bashrc
IPV4:
.acme.sh/acme.sh --issue -d 你的域名 --standalone -k ec-256
IPV6:
.acme.sh/acme.sh --issue -d 你的域名 --standalone -k ec-256 --server letsencrypt --listen-v6
.acme.sh/acme.sh --installcert -d 你的域名 --fullchainpath /etc/ssl/private/你的域名.crt --keypath /etc/ssl/private/你的域名.key --ecc
chmod 755 /etc/ssl/private
#(记得cret和key要有755的权限,没有就手动添加)
acme.sh --upgrade --auto-upgrade

2.https Nginx配置
server {
listen 80;
listen [::]:80;
server_name 你的域名;
rewrite ^/(.*)$ https://你的域名:443/$1 permanent;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name 你的域名;

root html;

ssl_certificate /etc/ssl/private/域名.crt; # pem文件的路径
ssl_certificate_key /etc/ssl/private/域名.key; # key文件的路径
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;#缓存有效期
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#安全链接可选的加密协议
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;#加密算法
ssl_prefer_server_ciphers on;#使用服务器端的首选算法

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

location / {
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

最后重启Nginx server:
systemctl restart nginx

3.设置证书自动签
cd
mkdir shell
cd shell
touch acme.sh
vim acme.sh
点击i,输入以下内容:
/root/.acme.sh/acme.sh --install-cert -d 你的域名 --ecc --fullchain-file /etc/ssl/private/你的域名.crt --key-file /etc/ssl/private/你的域名.key
chmod +r /etc/ssl/private/你的域名.key

保存后加权限
chmod +x acme.sh

设置自动任务
crontab -e

在里面输入以下代码,意思为每月1日自动申请证书
0 1 1 * * bash /root/shell/acme.sh

重启crontab:
/etc/init.d/cron restart

OK,流程全部走完了。

标签: 暂无
最后更新:2023年10月10日

free

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2024 EverythingIThink. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang