Setup Your Own TTRss

Author Avatar
Young Hug Apr 30, 2020

We need to protect our privacy currently in this big data world. We’re hardly to get we want. The information has exploded in our life. We need to filter the information we wanted now. Using RSS is a good choice to do that. And TTRss is a option to do that.

Docker Compose

We have a lot of options to setup TTRss. But the most convenient way is to use docker. We will expose four services. They are Postgres which is a database, TTRss, mercury which is plugin and nginx.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
version: "3"
networks:
default:
driver: bridge
services:
database.postgres:
image: postgres:alpine
container_name: Postgres
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=CHANGEME #default is pirss
volumes:
- ~/postgres/data/:/var/lib/postgresql/data # persist postgres data to ~/postgres/data/ on the host
restart: always

#Default admin/password
service.rss:
image: wangqiru/ttrss:arm32v7
container_name: TTRss
ports:
- 181:80
environment:
- SELF_URL_PATH=CHANGEME # please change to your own domain
- DB_HOST=database.postgres
- DB_PORT=5432
- DB_NAME=ttrss
- DB_USER=postgres
- DB_PASS=CHANGEME # please change the password; Web pwd hyyrss
#- ENABLE_PLUGINS=auth_internal,fever,search_sphinx
- ENABLE_PLUGINS=auth_internal,fever # auth_internal is required. Plugins enabled here will be enabled for all users as system plugins
- FETCH_TIMEOUT=60 #Need to change code
stdin_open: true
tty: true
restart: always
command: sh -c 'sh /wait-for.sh $$DB_HOST:$$DB_PORT -- php /configure-db.php && exec s6-svscan /etc/s6/'

service.mercury: # set Mercury Parser API endpoint to `service.mercury:3000` on TTRSS plugin setting page
image: wangqiru/mercury-parser-api:latest
container_name: Mercury
expose:
- 3000
restart: always
service.nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- 80:80
- 443:443
volumes:
- CHANGEME:/etc/nginx/nginx.conf:ro
- CHANGEME:/etc/ssl/custom

Note

The environment variable SELF_URL_PATH should be the site which you want to visit in your browser.

Nginx

Nginx is reverse proxy tool. Nginx will help to load balance, hide the real port and use https.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
user  nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

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;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;
#include /etc/nginx/conf.d/*.conf;

upstream ttrss {
server 127.0.0.1:5555;
keepalive 64
}

server {
listen 80;
server_name rss.younggod.club;
return 301 https://{HOSTNAME}$request_uri; #Rewrite to https.
# For http config
#location / {
# proxy_pass http://service.rss;
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#}
}

server {
listen 443 ssl;
gzip on;
server_name YourHostName; #Change To Your Host

ssl_certificate fullchain.pem; #public key
ssl_certificate_key privkey.pem; #private Key

#CloudFlare optional
#ssl_client_certificate /etc/ssl/certs/cloudflare.crt;
#ssl_verify_client on;

access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log;

location / {
proxy_redirect off;
proxy_pass http://service.rss;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;

client_max_body_size 100m;
client_body_buffer_size 128k;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}

}

Note:

Nginx is a container or binary code. Nginx can communicate with other container directly if nginx is a container.

Small Enhancements

There is a limitation that 15 seconds will be timeout of TTRss.

  1. Change code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # Add following line
    $function_path = '/var/www/include/functions.php';
    $fetch_timeout = env('FETCH_TIMEOUT',60);

    # At last of function if(dbcheckconn($config))
    file_put_contents($confpath, $contents);

    $contents = file_get_contents($function_path);
    $contents = preg_replace('/(define_default\(\'FILE_FETCH_CONNECT_TIMEOUT\',\s*)(\d+)(\);)/','${1}'.$fetch_timeout.'${3}',$contents);
    $contents = preg_replace('/(define_default\(\'FEED_FETCH_NO_CACHE_TIMEOUT\',\s*)(\d+)(\);)/','${1}'.$fetch_timeout.'${3}',$contents);
    file_put_contents($function_path, $contents);
  2. change environment

    1
    export FETCH_TIMEOUT=60
  3. restart container

Note:

This change can be updated in the docker image.

Plugins

You can install plugins.

How to install

You can follow the workflow:

1
2
3
4
5
6
7
8
# Go to the plugins.local fold
cd {tt-rss}/plugins.local
# Download plugins
git clone {Plugins}
# Rename the fold
mv {origin_fold_name} {right_fold_name}
# Refresh in the UI
click the refresh button in the UI and you will see the plugin is in the UI.

Note:

The fold name must be fit with the plugin name in the {plugin}/init.php and the fold name must be lowercase and _.

e.g:

The name of plugin is Af_Zz_NoAutoPlay. The fold name should be af_zz_noautoplay.

How to remove

There are two ways to remove the plugins:

  1. You can delete the plugin in the UI
  2. You can remove the files of plugin.

FAQ

There’re some normal issues. The solutions are as follows.

Using docker-compose

Run docker-compose to up services.

1
2
3
4
5
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD:$PWD" \
-w="$PWD" \
docker/compose:1.24.0 up

Save docker-compose as an alias:

1
2
3
4
5
6
echo alias docker-compose="'"'docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD:$PWD" \
-w="$PWD" \
docker/compose:1.24.0'"'" >> ~/.bashrc
Source ~/.bashrc

Dump SQL Data

Dump SQL Data from Postgres Database

1
docker exec {Container_Name} pg_dumpall -c -U postgres > export.sql

Note:

-u: username of the postgres database.

Restore SQL Data

Restore the SQL Data to Postgres Database

1
cat export.sql | docker exec -i {Container_Name} psql -U postgres

Upload File To VPS

using scp

1
scp -i ~/.ssh/id_rsa file  RemoteHostName@IP:PATH

We also can use scp to download the file from VPS.

DNS ISSUE

add a nameserver to resolve the hostname

1
2
3
4
vi /etc/resolv.conf

#Add the following line
nameserver 8.8.8.8

This blog is under a CC BY-NC-SA 3.0 Unported License
Link to this article: https://younggod.netlify.app/2020/04/30/practice/TTRss/