Ghost6.0配置Nginx以启用Activitypub

Ghost6.0配置Nginx以启用Activitypub

Photo by Swello / Unsplash

开发了这么久,Ghost6.0终于上线了。

但是大家期待已久的Activitypub支持在我体验了一番后,感觉又像是鸡肋一样。可能之前是我用Cloudflare Worker和Gotosocial已经实现了近似的效果把?

  1. 以你博客域名的方式加入宇宙联邦,账号可以被关注、评论、点赞、转发等等基础操作。
  2. 发文自动发嘟,以敏感内容方式显示文章主题内容(没有图片)。
  3. 但是暂时不支持第三方Activitypub客户端登录。

目前可以通过Docker升级、CLI升级,虽然在升级后默认情况下不用修改任何文件也能使用网站的功能。

但是升级以后大概率会出现Activitypub页面无法打开报错的情况,经过一番排查后发现是因为6.0后改动太大,除全新安装以外,都需要对反代工具进行重新配置,如果想在Nginx下使用需要自己在手动修改一下Nginx的conf文件。

不过官方目前也在更新了,最新版的cli工具已经支持自动修改conf文件了。

我们只需要打开你博客的nginx conf文件,将对Activitypub的请求做一个简单响应即可。

Nginx conf的配置文件路径通常为 /etc/nginx/sites-available/1900.live.conf ,通过使用 sudo nano 命令进行修改,并增加对 /.ghost/activitypub/*/.well-known/ 访问链接的重写,指向Activitypub后端服务。

如果不想搭建后端可以使用Ghost官方的服务 https://ap.ghost.org 即可。

server {
listen 80;   
server_name 1900.live; 
if ($scheme = http) {
    return 301 https://$host$request_uri;
}
}

server {
listen              443 ssl;  
server_name         1900.live;

include snippets/ssl-params.conf;
# include snippets/ghost-activitiypub.conf; # 你也可以通过引入代码段方式

gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;


# 增加以下内容 ---------------------------
location ~ /.ghost/activitypub/* {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_ssl_server_name on;
    proxy_pass https://ap.ghost.org;
}

location ~ /.well-known/(webfinger|nodeinfo) {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_ssl_server_name on;
    proxy_pass https://ap.ghost.org;
}
# 增加以上内容 ---------------------------

location / {
    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_ssl_server_name on;
    index index.html;
}

location /rss/ {
    rewrite ^/rss/?$ /rss.xml last;
}
 
location /ghost/ {
    proxy_pass http://cms.1900.live/ghost/;
    proxy_set_header Host cms.1900.live;
}

location ~ ^/(.*)/edit {
    proxy_pass http://cms.1900.live/$1/edit;
    proxy_set_header Host cms.1900.live;
}


error_page 404 /404.html;
error_page 500 /505.html; 
	    
client_max_body_size 50m;
}

但是官方服务有一定的限制,如果你不希望有这些限制也可以用过 https://github.com/TryGhost/ghost-docker 项目中的 Activitypub 部分自建后端服务。

Enjoy!

来自联邦宇宙的回应

加入评论