Created
May 10, 2019 09:30
-
-
Save lize240810/3a586cf8cf1ce56c27873d1e8e0350cd to your computer and use it in GitHub Desktop.
在服务器上运行项目以后让项目绑定域名并且生成https证书
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.安装必要库 | |
| ``` | |
| apt-get -y install git bc | |
| ``` | |
| 2.下载生成ssl证书的项目 | |
| ``` | |
| git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt | |
| ``` | |
| 3.继续生成证书必须要先停止现在的nginx | |
| ``` | |
| service nginx stop | |
| ``` | |
| 4.进入到项目中 | |
| ``` | |
| cd /letsencrypt | |
| ``` | |
| 5.运行库 | |
| ``` | |
| ./letsencrypt-auto certonly --standalone | |
| ``` | |
| > 运行库之后需要等待几分钟 会给出如下信息 | |
| ``` | |
| Saving debug log to /var/log/letsencrypt/letsencrypt.log | |
| Enter email address (used for urgent renewal and security notices) (Enter 'c' to | |
| cancel): 你的email地址 | |
| ——————————————————————————- | |
| Please read the Terms of Service at | |
| https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree | |
| in order to register with the ACME server at | |
| https://acme-v01.api.letsencrypt.org/directory | |
| ------------------------------------------------------------------------------- | |
| (A)gree/(C)ancel: A | |
| ——————————————————————————- | |
| Would you be willing to share your email address with the Electronic Frontier | |
| Foundation, a founding partner of the Let's Encrypt project and the non-profit | |
| organization that develops Certbot? We'd like to send you email about EFF and | |
| our work to encrypt the web, protect its users and defend digital rights. | |
| ------------------------------------------------------------------------------- | |
| (Y)es/(N)o: Y | |
| 之后会提示输入域名,本例为www.itkylin.com,若有多个子域名,以空格隔开。 | |
| Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' | |
| to cancel):www.itkylin.com | |
| ``` | |
| > 成功信息 Obtaining a new certificate | |
| Performing the following challenges: | |
| tls-sni-01 challenge for www.itkylin.com | |
| Waiting for verification... | |
| Cleaning up challenges | |
| 6.查看证书 | |
| > 切换到root用户下 | |
| ``` | |
| cd /etc/letsencrypt/live/www.itkylin.com | |
| ``` | |
| 7.生成解析ssl证书的txt | |
| ``` | |
| sudo apt-get install certbot | |
| sudo certbot certonly -d *.lize98.top -d lize98.top --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory | |
| # 把 lize98.top 修改为自己的域名就可以了 | |
| ``` | |
| > 之后会出现两个密匙 直接进行在下面的阿里云域名中添加记录就可以 | |
| 8.解析阿里云中的域名 | |
| [阿里云解析地址](https://dns.console.aliyun.com/?spm=5176.12818093.recent.ddns.488716d05FtpdL#/dns/domainList) | |
|  | |
| 6. 替换或者生成conf | |
| ``` | |
| vim /etc/nginx/conf.d/demo.conf | |
| ``` | |
| ``` | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name wx.lize98.top; # 域名 | |
| return 301 https://$host$request_uri; | |
| } | |
| server { | |
| listen 443 ssl; | |
| listen [::]:443 ssl; | |
| if ($host != "wx.lize98.top") { | |
| return 301 https://wx.lize98.top; | |
| } | |
| server_name wx.lize98.top; | |
| ssl_certificate /etc/letsencrypt/live/wx.lize98.top/fullchain.pem; | |
| ssl_certificate_key /etc/letsencrypt/live/wx.lize98.top/privkey.pem; | |
| ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
| ssl_prefer_server_ciphers on; | |
| ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; | |
| location / { | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header Host $http_host; | |
| proxy_set_header X-NginX-Proxy true; | |
| proxy_pass http://127.0.0.1:8888/; # 运行端口 | |
| proxy_redirect off; | |
| } | |
| } | |
| ``` | |
| 9.重启项目 | |
| > supervisor 操作 | |
| ``` | |
| # 重新加载配置 | |
| sudo supervisorctl reload | |
| # 查看进程状态 | |
| sudo supervisorctl status | |
| # 停止/启动/重启某个进程(此处为demo) | |
| sudo supervisorctl stop/start/restart demo | |
| ``` | |
| > nginx 操作 | |
| ``` | |
| # 重启nginx服务(会重新加载配置文件) | |
| sudo service nginx restart | |
| # 启动、停止服务器 | |
| sudo service nginx start/stop | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment