ChenSmallX / ChenSmallX.github.io

My blog on github
1 stars 0 forks source link

使用docker-compose搭建nextcloud+Nginx+MySQL+Redis | Case of Xeon #67

Open ChenSmallX opened 3 years ago

ChenSmallX commented 3 years ago

https://hexo.chensmallx.top/2021/04/08/nextcloud-on-docker/

使用docker-compose搭建nextcloud+Nginx+MySQL+Redis

coloraven commented 3 years ago

仅仅使用MySQL+nextcloud容器的模式与博主的模式,性能上有多大差异?

ChenSmallX commented 3 years ago

@sirliu 仅仅使用MySQL+nextcloud容器的模式与博主的模式,性能上有多大差异?

对于性能上的差异就在于没有redis做文件锁和缓存,如果host的磁盘io比较强的话,没有redis也是可以的,nginx主要是用来提高安全性

ChengzhiMiao commented 2 years ago

大佬 我弄完之后出现了502 Bad Gateway,遇到过吗?

ChenSmallX commented 2 years ago

@ChengzhiMiao 大佬 我弄完之后出现了502 Bad Gateway,遇到过吗?

nginx 的 502 bad gateway 一般是后端程序无响应造成的。

  1. 你看看 nextcloud 的容器有没有起来,起来的话用 docker logs [container id 容器ID] 或者 docker exec -it [container id or name 容器id或容器名] /bin/bash 进去看看容器内的日志或情况,如果服务没正常起来的话,就尝试重拉镜像,重开容器,或者调整一下映射目录,映射的目录无法读写的话,也是没法正常工作的。
  2. 如果上面不行,你就看看是不是端口映射环节出了问题,我这一套 docker-compose.yml 里头除了 nginx 的端口以外,其他的都只在这几个 docker 容器之间共享,没有真实映射到物理机里面,可以尝试从服务和端口入手看看。
ChenSmallX commented 2 years ago

@ChengzhiMiao 大佬 我弄完之后出现了502 Bad Gateway,遇到过吗?

嗷,还可能是 nginx 配置的问题,在 upstream 里面配置的 server 地址需要填写你在 docker-compose.yml 里面写的 [容器名]:[端口] 。我这里 nextcloud 的容器名称叫 app ,所以 server 的地址就是 app:9000

upstream php-handler {
    server app:9000;
}
ChengzhiMiao commented 2 years ago

您这个很详细,我搭建出来了,我把onlyoffice也弄好了,但是集成还有是有些出入。

ChenSmallX commented 2 years ago

@ChengzhiMiao 您这个很详细,我搭建出来了,我把onlyoffice也弄好了,但是集成还有是有些出入。

您还有什么问题呀,我也一起看看有没有什么方法可以解决

我也是比较偏向搭建一开始就把环境弄到自己觉得满意为止比较好 :joy:

ChengzhiMiao commented 2 years ago

大佬 方便使用麦克风交流 ?

ChenSmallX commented 2 years ago

@ChengzhiMiao 大佬 方便使用麦克风交流 ?

在上班呢,不太方便,尽量文字描述吧 :rofl:

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao 大佬 方便使用麦克风交流 ?

在上班呢,不太方便,尽量文字描述吧 :rofl:

好的,等你有时间吧,我也是上班摸了一条鱼部署了一下,感觉不是一下就能说清楚的。

ChenSmallX commented 2 years ago

@ChengzhiMiao

@ChenSmallX

@ChengzhiMiao 大佬 方便使用麦克风交流 ?

在上班呢,不太方便,尽量文字描述吧 :rofl:

好的,等你有时间吧,我也是上班摸了一条鱼部署了一下,感觉不是一下就能说清楚的。

时间确实是有时间,不过就是没法语音交流 :joy:

而且文字描述可以贴代码和贴图,感觉看起来更方便一些,如果觉得博客的 gitalk 不太好写,可以到文章对应的 github issue 里面写

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

@ChenSmallX

@ChengzhiMiao 大佬 方便使用麦克风交流 ?

在上班呢,不太方便,尽量文字描述吧 :rofl:

好的,等你有时间吧,我也是上班摸了一条鱼部署了一下,感觉不是一下就能说清楚的。

时间确实是有时间,不过就是没法语音交流 :joy:

而且文字描述可以贴代码和贴图,感觉看起来更方便一些,如果觉得博客的 gitalk 不太好写,可以到文章对应的 github issue 里面写

你动态里面的图片显示正常呢 ?

ChenSmallX commented 2 years ago

@ChengzhiMiao

你动态里面的图片显示正常呢 ?

我动态里面展示图片是正常的,

我觉得可能是 nginx 或者是 https 的问题,你可以在浏览器 f12 抓包看看返回情况。或者是在 nginx 的容器里面抓包看看。

image

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

你动态里面的图片显示正常呢 ?

我动态里面展示图片是正常的,

我觉得可能是 nginx 或者是 https 的问题,你可以在浏览器 f12 抓包看看返回情况。或者是在 nginx 的容器里面抓包看看。

image

嗯,我和你用的是相同的配置文件,可能是我在群晖上的原因吧。 index.js:46 No OC found Fr @ index.js:46 jquery-migrate.min.js:2 JQMIGRATE: Migrate is installed, version 3.3.2 globals.js:62 jQuery is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 2globals.js:62 jQuery is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 ProxyBus.ts:17 Proxying an event bus of version 1.3.0 with 2.0.0 t @ ProxyBus.ts:17 3globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 App.vue:381 Notifications permissions not yet requested globals.js:62 Handlebars is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 2globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 session-heartbeat.js:101 session heartbeat polling started 10globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 globals.js:62 Clipboard is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 8globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 globals.js:62 moment is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 2util.js:123 OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment formatDate @ util.js:123 globals.js:62 moment is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 util.js:123 OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment formatDate @ util.js:123 globals.js:62 moment is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 util.js:123 OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment formatDate @ util.js:123 globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 util.js:123 OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment formatDate @ util.js:123 util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment relativeModifiedDate @ util.js:135 globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 globals.js:62 moment is deprecated: please ship your own, this will be removed in Nextcloud 20 ue @ globals.js:62 2util.js:123 OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment formatDate @ util.js:123 util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment relativeModifiedDate @ util.js:135 5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own. ue @ globals.js:62 8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment relativeModifiedDate @ util.js:135 (anonymous) @ init.js:101 each @ jquery.js:354 each @ jquery.js:189 (anonymous) @ init.js:100

ChenSmallX commented 2 years ago

@ChengzhiMiao

只看你最后几行的报错,看起来像是前端缺了某些 js 函数或者什么的,我不会前端,爱莫能助了。

See @nextcloud/moment
formatDate @ util.js:123
util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.
ue @ globals.js:62
8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
(anonymous) @ init.js:101
each @ jquery.js:354
each @ jquery.js:189
(anonymous) @ init.js:100
ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

只看你最后几行的报错,看起来像是前端缺了某些 js 函数或者什么的,我不会前端,爱莫能助了。

See @nextcloud/moment
formatDate @ util.js:123
util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.
ue @ globals.js:62
8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
(anonymous) @ init.js:101
each @ jquery.js:354
each @ jquery.js:189
(anonymous) @ init.js:100

没事,回头我再捣鼓一下,那你这个应该都是正常的,你可以把onlyoffice加上,可以实现在线编辑word,excel,PDF;也可以多用户同时编辑一个文档。更完美。

@ChenSmallX

@ChengzhiMiao

只看你最后几行的报错,看起来像是前端缺了某些 js 函数或者什么的,我不会前端,爱莫能助了。

See @nextcloud/moment
formatDate @ util.js:123
util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.
ue @ globals.js:62
8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
(anonymous) @ init.js:101
each @ jquery.js:354
each @ jquery.js:189
(anonymous) @ init.js:100

@ChenSmallX

@ChengzhiMiao

只看你最后几行的报错,看起来像是前端缺了某些 js 函数或者什么的,我不会前端,爱莫能助了。

See @nextcloud/moment
formatDate @ util.js:123
util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.
ue @ globals.js:62
8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
(anonymous) @ init.js:101
each @ jquery.js:354
each @ jquery.js:189
(anonymous) @ init.js:100

@ChenSmallX

@ChengzhiMiao

只看你最后几行的报错,看起来像是前端缺了某些 js 函数或者什么的,我不会前端,爱莫能助了。

See @nextcloud/moment
formatDate @ util.js:123
util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
5globals.js:62 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.
ue @ globals.js:62
8util.js:135 OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment
relativeModifiedDate @ util.js:135
(anonymous) @ init.js:101
each @ jquery.js:354
each @ jquery.js:189
(anonymous) @ init.js:100
ChenSmallX commented 2 years ago

@ChengzhiMiao

没事,回头我再捣鼓一下,那你这个应该都是正常的,你可以把onlyoffice加上,可以实现在线编辑word,excel,PDF;也可以多用户同时编辑一个文档。更完美。

碰到国内下不到插件的情况下,可以尝试手动安装插件的方法,装了之后就不用管升级了,自动升级也升级不上去。
它下载插件是直接从 github release 拉的。

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

没事,回头我再捣鼓一下,那你这个应该都是正常的,你可以把onlyoffice加上,可以实现在线编辑word,excel,PDF;也可以多用户同时编辑一个文档。更完美。

碰到国内下不到插件的情况下,可以尝试手动安装插件的方法,装了之后就不用管升级了,自动升级也升级不上去。
它下载插件是直接从 github release 拉的。

是的,可以离线现在app,然后上传到目录,再启用就好了,然后再把onlyoffice的url放进去就好了。

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

没事,回头我再捣鼓一下,那你这个应该都是正常的,你可以把onlyoffice加上,可以实现在线编辑word,excel,PDF;也可以多用户同时编辑一个文档。更完美。

碰到国内下不到插件的情况下,可以尝试手动安装插件的方法,装了之后就不用管升级了,自动升级也升级不上去。
它下载插件是直接从 github release 拉的。

大佬,我是centos 7 的 啥时候有空给远程看看吗?

ChenSmallX commented 2 years ago

@ChengzhiMiao

大佬,我是centos 7 的 啥时候有空给远程看看吗?

是什么问题呢?

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

大佬,我是centos 7 的 啥时候有空给远程看看吗?

是什么问题呢?

我把mariadb 换成了mysql现在正常了,谢超级大佬

ChengzhiMiao commented 2 years ago

@ChenSmallX

@ChengzhiMiao

大佬,我是centos 7 的 啥时候有空给远程看看吗?

是什么问题呢?

大佬,我又回来了,我在集成onlyoffice的时候出现了下面报错,你遇到过吗?单独打开onlyoffice是正常的。

连接是发生异常 (文档服务内部发生异常: Error while downloading the document file to be converted.) (版本 6.4.2.6)

ChenSmallX commented 2 years ago

@ChengzhiMiao

@ChenSmallX

@ChengzhiMiao

大佬,我是centos 7 的 啥时候有空给远程看看吗?

是什么问题呢?

大佬,我又回来了,我在集成onlyoffice的时候出现了下面报错,你遇到过吗?单独打开onlyoffice是正常的。

连接是发生异常 (文档服务内部发生异常: Error while downloading the document file to be converted.) (版本 6.4.2.6)

这看起来像是 onlyoffice 自身的报错,可能是网络问题在 downloading 时产生了错误。

ChengzhiMiao commented 2 years ago

现在都基本弄好了,谢谢大佬。

ghost commented 2 years ago

网站配置数据库时,提示Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory 是什么原因?数据目录已经改成/var/www/html/db,且配置文件没修改过除密码外的东西

ChenSmallX commented 2 years ago

@lius1999 网站配置数据库时,提示Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory 是什么原因?数据目录已经改成/var/www/html/db,且配置文件没修改过除密码外的东西

nextcloud 的容器里面没有 /var/www/html/db 这个路径吧。
你用的数据库也是容器版的 mysql 嘛?在创建docker容器的时候把这几个容器互相映射一下,在容器里面就可以用容器名互相访问了。完全不用自己管 mysql 容器里面是怎么运行的呀

ghost commented 2 years ago

谢谢,刚才对原文理解有误,已经解决了,不过又出现了一个新的问题…… Error while trying to initialise the database: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.

ChenSmallX commented 2 years ago

@lius1999

谢谢,刚才对原文理解有误,已经解决了,不过又出现了一个新的问题…… Error while trying to initialise the database: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.

网上搜这个报错挺多解决方法的呀,尝试一下这个:

在docker运行maraidb的指令添加
--skip-innodb-read-only-compressed
即可正常执行

https://blog.csdn.net/m0_46135899/article/details/120774672

或者在这里碰碰运气,nextcloud 官方论坛也有解决办法:

https://help.nextcloud.com/t/update-to-next-cloud-21-0-2-has-get-an-error/117028/4
https://dba.stackexchange.com/questions/256427/unable-to-create-tables-with-row-format-compressed

ghost commented 2 years ago

@lius1999

谢谢,刚才对原文理解有误,已经解决了,不过又出现了一个新的问题…… Error while trying to initialise the database: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.

网上搜这个报错挺多解决方法的呀,尝试一下这个:

在docker运行maraidb的指令添加 --skip-innodb-read-only-compressed 即可正常执行

https://blog.csdn.net/m0_46135899/article/details/120774672

或者在这里碰碰运气,nextcloud 官方论坛也有解决办法:

https://help.nextcloud.com/t/update-to-next-cloud-21-0-2-has-get-an-error/117028/4 https://dba.stackexchange.com/questions/256427/unable-to-create-tables-with-row-format-compressed

感谢,确实能够正常运行了

YuJian920 commented 2 years ago

大佬,因为宿主机中已经有Nginx了,于是决定用docker + Nginx的办法安装nextcloud,但是全部部署完之后怎么也打不开nextcloud的第一次设置页面,不管是IP打开还是域名打开,但是不使用fpm版本就是正常的,怀疑是不是宿主机的Nginx需要配置一下fpm环境?

ChenSmallX commented 2 years ago

@YuJian920 大佬,因为宿主机中已经有Nginx了,于是决定用docker + Nginx的办法安装nextcloud,但是全部部署完之后怎么也打不开nextcloud的第一次设置页面,不管是IP打开还是域名打开,但是不使用fpm版本就是正常的,怀疑是不是宿主机的Nginx需要配置一下fpm环境?

应该不是,fpm版本和普通版本的区别就在于普通版本的镜像里面带了个nginx,fpm是直接用php跑的后端进程。
用IP+端口的方式也没法直接访问容器吗?看看是不是端口没映射出来到宿主机

YuJian920 commented 2 years ago

@ChenSmallX

@YuJian920 大佬,因为宿主机中已经有Nginx了,于是决定用docker + Nginx的办法安装nextcloud,但是全部部署完之后怎么也打不开nextcloud的第一次设置页面,不管是IP打开还是域名打开,但是不使用fpm版本就是正常的,怀疑是不是宿主机的Nginx需要配置一下fpm环境?

应该不是,fpm版本和普通版本的区别就在于普通版本的镜像里面带了个nginx,fpm是直接用php跑的后端进程。
用IP+端口的方式也没法直接访问容器吗?看看是不是端口没映射出来到宿主机

docker-compose.yml中的app那里的expose: - "9000",我改成了ports:- 7788:9000,应该是没有问题的,但是我直接IP + 端口访问,容器日志里什么变化也没有,还真有可能是这里出错了

ChenSmallX commented 2 years ago

@YuJian920

@ChenSmallX

@YuJian920 大佬,因为宿主机中已经有Nginx了,于是决定用docker + Nginx的办法安装nextcloud,但是全部部署完之后怎么也打不开nextcloud的第一次设置页面,不管是IP打开还是域名打开,但是不使用fpm版本就是正常的,怀疑是不是宿主机的Nginx需要配置一下fpm环境?

应该不是,fpm版本和普通版本的区别就在于普通版本的镜像里面带了个nginx,fpm是直接用php跑的后端进程。
用IP+端口的方式也没法直接访问容器吗?看看是不是端口没映射出来到宿主机

docker-compose.yml中的app那里的expose: - "9000",我改成了ports:- 7788:9000,应该是没有问题的,但是我直接IP + 端口访问,容器日志里什么变化也没有,还真有可能是这里出错了

我大概是知道咋回事了。
expose是容器和容器之间共享端口用的,如果要把容器里的端口映射到宿主机,要用ports,具体参考我上面配置文件里面nginx的端口处理方法

YuJian920 commented 2 years ago

@YuJian920

@ChenSmallX

@YuJian920 大佬,因为宿主机中已经有Nginx了,于是决定用docker + Nginx的办法安装nextcloud,但是全部部署完之后怎么也打不开nextcloud的第一次设置页面,不管是IP打开还是域名打开,但是不使用fpm版本就是正常的,怀疑是不是宿主机的Nginx需要配置一下fpm环境?

应该不是,fpm版本和普通版本的区别就在于普通版本的镜像里面带了个nginx,fpm是直接用php跑的后端进程。 用IP+端口的方式也没法直接访问容器吗?看看是不是端口没映射出来到宿主机

docker-compose.yml中的app那里的expose: - "9000",我改成了ports:- 7788:9000,应该是没有问题的,但是我直接IP + 端口访问,容器日志里什么变化也没有,还真有可能是这里出错了

我大概是知道咋回事了。 expose是容器和容器之间共享端口用的,如果要把容器里的端口映射到宿主机,要用ports,具体参考我上面配置文件里面nginx的端口处理方法

emmmm,我确实是改成ports啦

ChenSmallX commented 2 years ago

@YuJian920

emmmm,我确实是改成ports啦

那这确实有点难排障🧐 看看防火墙是不是开了端口?或者是是不是只监听了ipv6而没监听ipv4🤨

YuJian920 commented 2 years ago

@YuJian920 emmmm,我确实是改成ports啦

那这确实有点难排障🧐 看看防火墙是不是开了端口?或者是是不是只监听了ipv6而没监听ipv4🤨

最后还是放弃了,不用nextcloud了,1C1G的机器跑这个内存直接吃掉三分之二,太夸张了,用fpm版的是想着可能更省性能一些😭

ChenSmallX commented 2 years ago

@YuJian920

@YuJian920 emmmm,我确实是改成ports啦

那这确实有点难排障🧐 看看防火墙是不是开了端口?或者是是不是只监听了ipv6而没监听ipv4🤨

最后还是放弃了,不用nextcloud了,1C1G的机器跑这个内存直接吃掉三分之二,太夸张了,用fpm版的是想着可能更省性能一些😭

1c1g确实有点顶不住了😨
光一个docker就要吃掉不少,更别说带这么多容器了😨
我的机器是2c2g,而且是cpu型按量付费,性能强了一点点,但是日常跑nextcloud感觉还是有点卡慢

yinyu985 commented 2 years ago

您好,Nginx不太懂,假如我没有域名,没有SSL证书怎么办呢?

ChenSmallX commented 2 years ago

@yinyu985 您好,Nginx不太懂,假如我没有域名,没有SSL证书怎么办呢?

如果你不需要https,只用http的话,是可以不用nginx的。没有域名和证书的话,也是没法开启正确的https的,因为https就是跟访问的域名个证书绑定的。

yinyu985 commented 2 years ago

好的,感谢回复。

SmallXeon @.***> 于2022年1月21日周五 17:23写道:

@yinyu985 https://github.com/yinyu985 您好,Nginx不太懂,假如我没有域名,没有SSL证书怎么办呢?

如果你不需要https,只用http的话,是可以不用nginx的。没有域名和证书的话,也是没法开启正确的https的,因为https就是跟访问的域名个证书绑定的。

— Reply to this email directly, view it on GitHub https://github.com/ChenSmallX/ChenSmallX.github.io/issues/67#issuecomment-1018328505, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMMVUROLRZGUB4DEIQV7GLDUXEQZ3ANCNFSM5AR4DCCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

huangwb8 commented 2 years ago

大佬,你的方案很有吸引力!

我已经折腾出用nextcloud:latest的方案,但是我不知道这样会不会带来较大的性能损失:https://blognas.hwb0307.com/linux/docker/234

我平时是通过Nginx proxy manager来管理ssl证书和反向代理。所以我希望可以从这个教程中取取经。

我所有东西都很顺,唯独在Nginx设置上走不通:


# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
add_header Strict-Transport-Security  15552000;
#add_header X-Frame-Options SAMEORIGIN;

# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;

# Path to the root of your installation
root /var/www/html;

# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
location /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
}
location /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
}

# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
# pagespeed off;

location / {
    rewrite ^ /index.php$request_uri;
}

location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
    deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
    deny all;
}

# 这一段暂时有问题
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
    try_files $uri/ =404;
    index index.php;
}

# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
    try_files $uri /index.php$request_uri;
    add_header Cache-Control "public, max-age=15778463";
    # Add headers to serve security related headers (It is intended to
    # have those duplicated to the ones above)
    # Before enabling Strict-Transport-Security headers please read into
    # this topic first.
    #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    #
    # WARNING: Only add the preload option once you read about
    # the consequences in https://hstspreload.org/. This option
    # will add the domain to a hardcoded list that is shipped
    # in all major browsers and getting removed from this list
    # could take several months.
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
    add_header Referrer-Policy no-referrer;

    # Optional: Don't log access to assets
    access_log off;
}

location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
    try_files $uri /index.php$request_uri;
    # Optional: Don't log access to other assets
    access_log off;
}

如果我在Advanced里放一段:


location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

反代就会处理offline状态。

大佬能不能帮忙测试一下这个流程?谢谢了!真的折腾了好久了,一直没能成功!

ChenSmallX commented 2 years ago

@huangwb8 大佬,你的方案很有吸引力!

我已经折腾出用nextcloud:latest的方案,但是我不知道这样会不会带来较大的性能损失:https://blognas.hwb0307.com/linux/docker/234

我平时是通过Nginx proxy manager来管理ssl证书和反向代理。所以我希望可以从这个教程中取取经。

我所有东西都很顺,唯独在Nginx设置上走不通:


# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
add_header Strict-Transport-Security  15552000;
#add_header X-Frame-Options SAMEORIGIN;

# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;

# Path to the root of your installation
root /var/www/html;

# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
location /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
}
location /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
}

# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
# pagespeed off;

location / {
    rewrite ^ /index.php$request_uri;
}

location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
    deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
    deny all;
}

# 这一段暂时有问题
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
    try_files $uri/ =404;
    index index.php;
}

# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
    try_files $uri /index.php$request_uri;
    add_header Cache-Control "public, max-age=15778463";
    # Add headers to serve security related headers (It is intended to
    # have those duplicated to the ones above)
    # Before enabling Strict-Transport-Security headers please read into
    # this topic first.
    #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    #
    # WARNING: Only add the preload option once you read about
    # the consequences in https://hstspreload.org/. This option
    # will add the domain to a hardcoded list that is shipped
    # in all major browsers and getting removed from this list
    # could take several months.
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
    add_header Referrer-Policy no-referrer;

    # Optional: Don't log access to assets
    access_log off;
}

location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
    try_files $uri /index.php$request_uri;
    # Optional: Don't log access to other assets
    access_log off;
}

如果我在Advanced里放一段:


location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

反代就会处理offline状态。

大佬能不能帮忙测试一下这个流程?谢谢了!真的折腾了好久了,一直没能成功!

测试是肯定没办法帮你测试的😂但是看你的 nginx 配置,确实是有点问题。

docker搭建的php站点在使用nginx反代的时候是会遇到一些坑的,特别是要分清容器内使用的是 apache 网站服务器还是 php-fpm fastcgi 网站服务器。

首先要搞清楚你使用的 nextcloud:latest 内使用的服务器程序是什么,如果是 apache,那么就不能照抄我的这个配置或者相似的使用了 include fastcgi_params; 的配置,这个配置只适用于 php-fpm 的后端。

接着就是,如果你用的镜像确实是用的是 php-fpm 后端,那么你在 fastcgi_pass php-handler; 中引用到的代理目的地址 php-handler 在你的配置里面是没有定义的,这个引用值需要使用 upstream 定义之后再使用。

huangwb8 commented 2 years ago

@ChenSmallX

谢谢回复!

我用nextcloud:latest是成功的,它是apache。

我是想学您试试用nextcloud:fpm。不过没有成功

我看网上也有人问过类似的问题,不过他们都没有办法解决。

我按您的建议摸索一下吧!

ChenSmallX commented 2 years ago

@huangwb8 @ChenSmallX

谢谢回复!

我用nextcloud:latest是成功的,它是apache。

我是想学您试试用nextcloud:fpm。不过没有成功

我看网上也有人问过类似的问题,不过他们都没有办法解决。

我按您的建议摸索一下吧!

如果是 apache,那么就不需要使用 fastcgi 那一套了,直接按照正常的反向代理把请求头里面的host的地址改一下,加几个x-forward头,然后丢到 docker 里 apache 的端口上就可以了

ChenSmallX commented 2 years ago

@huangwb8 @ChenSmallX

谢谢回复!

我用nextcloud:latest是成功的,它是apache。

我是想学您试试用nextcloud:fpm。不过没有成功

我看网上也有人问过类似的问题,不过他们都没有办法解决。

我按您的建议摸索一下吧!

如果要使用 fpm 的后端,nginx反代还是会有一些坑的,特别是要做前后端动静态内容分离的时候。

我用 docker 的 fpm 后端搭建了几个站,比如 nextcloud 和 wordpress,遇到和填上的坑有好几个。我现在是在宿主机上安装 nginx,然后使用几个不同的 docker-compose 配置起了几个容器群,然后用宿主机的 nginx 分别代理几个容器的端口。

ChenSmallX commented 2 years ago

@too969

博主你好 我使用docker-compose在内网部署81端口访问系统后 想单独把nginx拎出来需要怎么做呢? 在容器中的nginx好像是通过 upstream php-handler 到app的 在宿主机安装nginx怎么把端口指向9000以及目录?

这要分两种做法,一个是nginx和docker容器在同个机器上,一个是nginx是单独的一台机器。

我只用过一种也是正在用的,就是nginx和docker容器在同个机器上(因为要用nginx同时代理多个docker容器)。这种情况下,对nginx的配置和nginx在容器里时差不多,只是有几个点需要注意:

  1. 选用nextcloud镜像的时候需要选择fpm版本的镜像,这样在nginx里头才能用fastcgi插件来方便地代理请求。
  2. 起nextcloud镜像时,可以随意地讲9000端口映射成其他端口。
  3. nginx配置中声明 upstream 的时候,host地址可以填127.0.0.1,port填写具体映射到宿主机的端口。
  4. nginx和docker容器在同一台物理机时,可以使用nginx来对静态资源加速,此时需要修改站点配置的 root 为docker容器中html路径在宿主机的映射,例如:root /home/docker/nextcloud_compose_dir/app/html;
  5. nginx在通过fastcgi插件对动态请求代理时,SCRIPT_FILENAME对应的是容器内的脚本位置,而不能更换为宿主机中的脚本位置,所以一般都是设置为fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;

其余的配置都和nginx在容器中一样即可。


至于第二种情况,nginx和docker容器不在同个机器上,这样就只能将所有的请求都代理到容器所在宿主机的端口,无法做静态资源加速了。

ChenSmallX commented 2 years ago

@too969 博主你好 我使用docker-compose在内网部署81端口访问系统后 想单独把nginx拎出来需要怎么做呢? 在容器中的nginx好像是通过 upstream php-handler 到app的 在宿主机安装nginx怎么把端口指向9000以及目录?

昨天我这hexo的gitalk出了点问题,不知道回复您有没有收到哈哈🥲

huangwb8 commented 2 years ago

@too969 我是用我自己的 那个比较简单的方案进行安装的,没有采用@ChenSmallX大佬的方案。所以可能帮不上忙喔!如果你感兴趣的话,可以看看我的安装方案,有几个小伙伴都可以成功安装的:https://blognas.hwb0307.com/linux/docker/234

duoyulee commented 2 years ago

想请教一下如果想用子域名访问部署的docker,nginx怎么配置比较好呢,在网上搜到的最后都失败了(っ °Д °;)っ

huangwb8 commented 2 years ago

想请教一下如果想用子域名访问部署的docker,nginx怎么配置比较好呢,在网上搜到的最后都失败了(っ °Д °;)っ

我一般都是使用Nginx Proxy Manager,对小白比较友好,证书管理和反代都很方便。有兴趣可以看看我的教程: https://blognas.hwb0307.com/linux/docker/604