0
来自 Discoze 社区
当前还没有回复,欢迎成为第一个参与讨论的人。
怕以后忘记怎么重新修改,这里记录一下操作过程,可能不适用CF的(CF官方有专用的模板文件和教程)
下面是加速CDN配置apps.yml:
text## The http or https CDN address for this Discourse instance (configured to pull) ## see https://meta.discourse.org/t/14857 for details DISCOURSE_CDN_URL: https://cdn.domain.com
在第三方CDN默认回源请求头有 X-Forwarded-For,不过还是建议自定义添加下面两个请求头:
| 请求头 | 请求内容 |
|---|---|
| X-Real-IP | %{remote_addr} |
| X-Forwarded-For | %{remote_addr} |
然后配置完成后我发现最近使用IP会变成容器IP:

下面是我的操作教程。
修改apps.yml文件,在run:中添加:
text- file: path: /etc/nginx/conf.d/outlets/server/set-real-ip-from-1panel.conf chmod: 644 contents: | set_real_ip_from 127.0.0.1; set_real_ip_from 172.16.0.0/12; - file: path: /etc/nginx/conf.d/outlets/server/real-ip-header.conf chmod: 644 contents: | real_ip_header x-forwarded-for; - file: path: /etc/nginx/conf.d/outlets/server/real-ip-recursive.conf chmod: 644 contents: | real_ip_recursive on;
其中172.16.0.0/12是容器IP
同时修改或者添加:
textDISCOURSE_TRUSTED_PROXIES: 127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
然后1Panel网站设置中需要开启真实IP,然后配置可能需要:
textreal_ip_header X-Forwarded-For; real_ip_recursive on; set_real_ip_from 0.0.0.0/0; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header REMOTE-HOST $remote_addr;
我只想加速静态资源怎么办?
那么就将静态资源全是映射到一个目录路径即可,然后回源设置路径:
text- file: path: /etc/nginx/conf.d/outlets/server/40-cdn-static-origin.conf chmod: 644 contents: | location ~ ^/__cdn_static_这个自定义八位数/(javascripts/|assets/|plugins/|fonts/|images/emoji/|uploads/|svg-sprite/|letter_avatar/|letter_avatar_proxy/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker|extra-locales/) { if ($request_method !~ ^(GET|HEAD)$) { return 405; } rewrite ^/__cdn_static_这个自定义八位数/(.*)$ /$1 last; } location = /__cdn_static_这个自定义八位数 { return 404; } location /__cdn_static_这个自定义八位数/ { return 404; }
然后回源设置回源路径:
text/__cdn_static_这个自定义八位数
这样原来cdn的域名访问就是404,静态资源正常访问了。