家用宽带一般来说都是不会给你开通公网IP的,但是也存在部分地区的例外,刚好我的宽带就有公网IP地址,并且IPv6地址也是可用的。
尽管如此,还是存在一些不好的地方,比如运营商会封禁我们的80端口和443端口,这样你就没有办法在家里搭建网站之类的东西,很是麻烦,我也是出于做微信小程序开发的需要才萌生了这样的念头。
我刚好手里有一个树莓派,就拿来做小程序的后台,于是才有了这篇博客来整理一下以后可能会用到的一些东西。
1、certbot 和aliyun-dns-certbot安装
pip3 install certbot certbot-nginx certbot-dns-aliyun
2、更新certificates
certbot certonly
-a certbot-dns-aliyun:dns-aliyun
--certbot-dns-aliyun:dns-aliyun-credentials /home/pi/certbot/credentials.ini
-d "*.blablabla.com"
--config-dir=/path/certbot/config
--work-dir=/path/certbot/work
--logs-dir=/path/certbot/logs
// 完整版本
certbot certonly -a certbot-dns-aliyun:dns-aliyun --certbot-dns-aliyun:dns-aliyun-credentials /home/pi/certbot/credentials.ini -d "*.blablabla.com" --config-dir=/path/certbot/config --work-dir=/path/certbot/work --logs-dir=/path/certbot/logs
credential.ini 文件
certbot_dns_aliyun:dns_aliyun_access_key = xxxxxxxxx
certbot_dns_aliyun:dns_aliyun_access_key_secret = xxxxxxxx
3、设置自动更新
// 打开crontab
crontab -e
// 在最后一行添加
0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /path/bin/certbot renew --config-dir=/path/certbot/config --work-dir=/path/certbot/work --logs-dir=/path/certbot/logs
4、nginx配置
由于我还没有搞清楚如何让他自动配置nginx,所以我自己手动配置的环境
server{
server_name demo.blabloa.com;
root /var/www/html/demo/web;
location /{
index index.php index.html index.htm;
try_files $uri /index.php$uri;
}
location ~ .+.php($|/){
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
listen [::]:9123 ssl;
listen 9123 ssl;
ssl_certificate /home/pi/certbot/config/live/blabloa.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /home/pi/certbot/config/live/blabloa.com/privkey.pem; # managed by Certbot
include /etc/nginx/options-ssl-nginx.conf; # managed by Certbot
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
暂无评论