cloudreve+nginx反向代理实现https访问,系统centos8.4
首先解决centos8.4的yum问题:(1条消息) 【无标题】【已解决】Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorlis_weixin_58982918的博客-CSDN博客
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum makecache
yum update -y
yum -y install vim
接着安装nginx,参考这篇文章:(1条消息) yum安装Nginx教程_不为码农的码农的博客-CSDN博客_yum安装nginx
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum info nginx
yum install nginx -y
开启80和443端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=80/udp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --zone=public --add-port=443/udp --permanent
firewall-cmd --reload
systemctl start nginx 启动nginx
浏览器访问nginx欢迎界面成功
主要参考:(1条消息) nginx如何配置https_footrip的博客-CSDN博客
cd /home/cloudreve/sslfornginx
openssl genrsa -out shidian.key 2048
openssl req -new -key shidian.key -out shidian.csr
openssl x509 -req -in shidian.csr -signkey shidian.key -out shidian.crt
主要的坑就是centos8.4的密钥必须2048字节,不然会报错
nginx: [emerg] SSL_CTX_use_certificate("/opt/server.crt") failed
(SSL: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small)
vi /etc/nginx/nginx.conf
将下面的默认注释掉的配置,去掉#号,并且写入crt和key两个文件的路径,就变成了下面所示
systemctl restart nginx 重启nginx
网页访问https的nginx成功。
如下图所示填入
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-TP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5212;
client_max_body_size 102400m;
}
其中client_max_body_size一定要写, 用Nginx反向代理服务器,进行附件相关的操作时,当文件大小超过1M,会出现413 Request Entity Too Large,这是由于nginx客户端默认的最大请求体是1M。参考:
(2条消息) NGINX 报错 413 Request Entity Too Large 解决方案_zhou神的博客-CSDN博客_nginx报错413
设置开机启动
cloudreve开机启动
vi /etc/rc.local末尾添加nohup /home/cloudreve/cloudreve353 &
nginx开机启动:
参考:CentOS 7 设置 Nginx 开机自启动_程序猿秃头之路的博客-CSDN博客_centos nginx自启动
如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令
systemctl enable nginx.service