背景:
从去年 2020 年底开始使用明道云,试运行一年时间,稳定可靠非常优秀。年底原华为云服务器到期,这里因为双 12 活动在华为云新买了一个 5 年期的服务器。 迁移完成后这里打算绑定域名不再用 IP 裸奔了。之前试过一次,按着官方教程走不是很顺利,这里准备再发起一轮进攻。 后面关于如何完成华为云的服务器迁移,有兴趣的可以评论,找时间再开一贴。
准备:
-
已经备案的域名。 如果你的服务器再大陆地区的话, 域名要记得备案哦。直接通过你的域名服务商备案就可以了。我再华为云这边,备案很方便。
-
SSL 证书。
- 申请证书。方法有很多,我用的是 digicert 的 dv baisc 免费证书。 华为控制台搜索 SSL 证书,然后去购买就可以了。。这里注意,这个证书不支持二级域名。 比如,如果你申请的是 abc.com, 然后你解析 oa.abc.com 到明道云,那么会提示证书不一致。 请在申请证书的时候,确保申请的域名和后面使用的一直。 如果你要用 oa.abc.com 那么申请的时候就申请 oa.abc.com。
- 下载证书。 下载后是一个压缩包,找到有 nignx 那个文件夹。 ,这个文件夹内的两个就是我们要用的。 注意,一个后缀是。cert, 一个是。key。 官方教程里面两个都显示的。pem 有一定误解。
-
云服务器安装 Nginx。因为我用的是云服务器镜像,没有默认装 Nginx, 所以需要自己手动重新装。 如果你已经安装过 Nginx 那么就直接去修改 nginx 的配置文件 Nginx.conf 文件。
- 看是不是装了 Nginx:
find / -name nginx.conf
, 如果像我这样就是没有装过。 找到的都是 docker 应用下的配置。 如果出现 /etc/nginx/nginx.conf 就对了,这个就是 Nginx 的配置文件路径。 - 安装 Nginx。
yum install nginx
- 看是不是装了 Nginx:
-
准备 SSH Secure File Transfer Client。 等会儿我们需要这个工具上传证书和 nginx.conf 文件。SSHSecureShellClient_downcc.zip
这是我新鲜下载的,之前讲 obs 帖子里面那个下载地址我昨天访问有点问题。 我就传一个包在这里,解压安装就 OK。 我也不晓得有没有毒,自己把防火墙打开在装吧。哈哈哈~
开始操作:
- 用 SSH Secure File Transfer Client 链接服务器。找到 Nginx 安装目录 把 Nginx.conf 下载到本地。
- 用 SSH Secure File Transfer Client 在 Nginx 目录下新建一个文件夹 ssl。用来存放证书,当然你也可以放在其他目录下,放在 Nginx 目录下方便管理。完成后如下图:
- 将证书上传到 ssl 文件夹。如图:
- 开始编辑第一步下载到本地的 Nginx.conf。
- 找到官方教程:https://docs.pd.mingdao.com/deployment/docker-compose/proxy.html。
- 找到官方给的 https Nginx 配置。 ATTENTIONS!!!!! 注意注意!!! 官网这个不是一个完整的 Nginx.conf 配置,所以不要全部替换掉你的 Nginx.conf。 我下面给的,就是完整配置
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
upstream mdy {
server 你的服务器公网IP:8880;
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# 强制跳转到https访问
server {
listen 80;
server_name 你准备的域名,注意要和证书一致;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name 你准备的域名,注意要和证书一致;
access_log /data/logs/weblogs/oa.tinoxchem.cn.log main;
error_log /data/logs/weblogs/oa.tinoxchem.cn.error.log;
ssl_certificate /etc/nginx/ssl/你的域名证书文件名称.crt;
ssl_certificate_key /etc/nginx/ssl/你的域名证书密钥文件名称.key;
underscores_in_headers on;
# 上传文件大小限制
client_max_body_size 2048m;
# 开启浏览器压缩,加速请求
gzip on;
gzip_proxied any;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 512;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript application/javascript application/octet-stream text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://mdy;
}
# IM 需要
location ~ /mds2 {
proxy_set_header Host $http_host;
proxy_hide_header X-Powered-By;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://mdy;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
-
保存后将这个 Nginx.conf 上传到服务器 Nginx 目录下覆盖原来的 Nginx.conf。
-
在云服务上重启 Nginx 服务。
cd /etc/nginx
nginx -c etc/nginx/nginx.conf
这里应该会报错,就是 nginx 配置里面的日志文件服务器上找不到。 我昨晚忘了截图了,按照提示的路径去新建文件就可以了。应该是三个。
-
用原来的 IP 访问系统,进入到安装管理器然后将访问域名设置成 https 后面是域名。
-
尝试用域名访问。出现新的问题
- 可以访问,但是部分资源加载失败。重新挂载一下 obs 配置文件。 参考:# 【小白教程】如何配置华为云 OBS 标准文件对象服务? 里面的第五步。
- 文件预览失败。 需要升级文件预览镜像。 参考:## 文档预览镜像升级
重启,大功告成。
特此鸣谢: 转角 heroes, 一九九九