[PAID] Install Discourse in Subfolder on Ubuntu Server

We have this website. we need to set up a subfolder discourse docker forum on ubuntu. We want to serve discourse on https://talkwithstranger.com/ask without using CDN.

I have tried to set it up by following this tutorial but I am having these problems

  1. Avatars disappears after 2 or 3 rebuilds
  2. Images uploaded on topics are giving 404 after some rebuilds

you have to fix bugs on this test domain so I can install and fix those same bugs on my live website 95% of work is done you just have to fix some bugs

My app.yml

##   Subfolder support with Docker   https://meta.discourse.org/t/subfolder-support-with-docker/30507

## discourse-terraform Docker configuration template

##

## After making changes to this file, you MUST rebuild for any changes

## to take effect in your live Discourse instance:

##

## /var/discourse/launcher rebuild app

##

## this is the all-in-one, standalone Discourse Docker container template

# You may add rate limiting to by commenting out the ratelimited template.

# Out of the box it allows 12 reqs a second per ip, and 100 per minute per ip

# This is configurable by amending the params in this file

templates:

  - "templates/postgres.template.yml"

  - "templates/redis.template.yml"

  - "templates/web.template.yml"

  - "templates/sshd.template.yml"

## which TCP/IP ports should this container expose?

expose:

  - "1357:80" #change this port to port where you want run discourse # fwd host port 80   to container port 80 (http)

  #- "2222:22" # fwd host port 2222 to container port 22 (ssh)

params:

  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to 1/3 of the memory you wish to allocate to postgres

  ## on 1GB install set to 128MB on a 4GB instance you may raise to 1GB

  db_shared_buffers: "512MB"

  #

  ## Which Git revision should this container use? (default: tests-passed)

  #version: tests-passed

env:

  LANG: en_US.UTF-8

  ## TODO: How many concurrent web requests are supported?

  ## With 2GB we recommend 3-4 workers, with 1GB only 2

  UNICORN_WORKERS: 3

  ##

  ## TODO: List of comma delimited emails that will be made admin and developer

  ## on initial signup example 'user1@example.com, user2@example.com'

  DISCOURSE_DEVELOPER_EMAILS: "ahmeds.works@gmail.com" #change these emails to site admins emails

  ##

  ## TODO: The domain name this Discourse instance will respond to

  DISCOURSE_RELATIVE_URL_ROOT: /ask 

  DISCOURSE_HOSTNAME: "privitevps.ga" #change this domain to you website domain

  ##

  ## TODO: The mailserver this Discourse instance will use

  # change smtp setting to your own smtp setting

  DISCOURSE_SMTP_ADDRESS: smtp.example.com

  DISCOURSE_SMTP_PORT: 587

  DISCOURSE_SMTP_USER_NAME: example@example.com

  DISCOURSE_SMTP_PASSWORD: example_password

##

  ## The CDN address for this Discourse instance (configured to pull)

  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## These containers are stateless, all data is stored in /shared

volumes:

  - volume:

      host: /var/discourse/shared/standalone

      guest: /shared

  - volume:

      host: /var/discourse/shared/standalone/log/var-log

      guest: /var/log

## The docker manager plugin allows you to one-click upgrade Discouse

## http://discourse.example.com/admin/docker

hooks:

  after_code:

    - exec:

        cd: $home/plugins

        cmd:

          - mkdir -p plugins

          - git clone https://github.com/discourse/docker_manager.git

          - git clone https://github.com/discourse/discourse-voting.git

## Remember, this is YAML syntax - you can only have one block with a name

run:

    - exec:

        cd: $home

        cmd:

          - rm -fr public/assets

          - sudo -E -u discourse bundle exec rake assets:precompile

          - mkdir -p public/ask

          - cd public/ask && ln -s ../uploads && ln -s ../backups

          - rm public/uploads

          - rm public/backups

    - replace:

       global: true

       filename: /etc/nginx/conf.d/discourse.conf

       from: proxy_pass http://discourse;

       to: |

          rewrite ^/(.*)$ /ask/$1 break;

          proxy_pass http://discourse;

    - replace:

       filename: /etc/nginx/conf.d/discourse.conf

       from: etag off;

       to: |

          etag off;

          location /ask {

             rewrite ^/ask/?(.*)$ /$1;

          }

    - replace:

         filename: /etc/nginx/conf.d/discourse.conf

         from: $proxy_add_x_forwarded_for

         to: $http_fastly_client_ip

         global: true

    - exec: echo "End of custom commands"

    - exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'

nginx config

location /ask {
    proxy_pass      http://localhost:1357;
    proxy_read_timeout      90;
    proxy_redirect  http://localhost:1357 https://privitevps.ga;
}

Discourse error log

    /var/www/discourse/app/models/report.rb:267:in `rescue in find'

    /var/www/discourse/app/models/report.rb:234:in `find'

    /var/www/discourse/app/controllers/admin/reports_controller.rb:42:in `block (2 levels) in bulk'

    actionpack-6.0.3.5/lib/action_controller/metal/strong_parameters.rb:345:in `block in each_pair'

    actionpack-6.0.3.5/lib/action_controller/metal/strong_parameters.rb:344:in `each_pair'

    actionpack-6.0.3.5/lib/action_controller/metal/strong_parameters.rb:344:in `each_pair'

    /var/www/discourse/app/controllers/admin/reports_controller.rb:31:in `block in bulk'

    /var/www/discourse/lib/hijack.rb:56:in `instance_eval'

    /var/www/discourse/lib/hijack.rb:56:in `block in hijack'

    /var/www/discourse/lib/scheduler/defer.rb:94:in `block in do_work'

    rails_multisite-2.5.0/lib/rails_multisite/connection_management.rb:76:in `with_connection'

    /var/www/discourse/lib/scheduler/defer.rb:89:in `do_work'

    /var/www/discourse/lib/scheduler/defer.rb:79:in `block (2 levels) in start_thread'

PostgreSQL log

2021-04-01 18:33:04.209 UTC [51] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-01 18:33:04.210 UTC [51] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-04-01 18:33:04.211 UTC [51] LOG:  listening on IPv6 address "::", port 5432
2021-04-01 18:33:04.211 UTC [51] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-01 18:33:04.223 UTC [73] LOG:  database system was shut down at 2021-04-01 18:32:19 UTC
2021-04-01 18:33:04.230 UTC [51] LOG:  database system is ready to accept connections
2021-04-01 18:44:16.543 UTC [1155] discourse@discourse LOG:  provided user name (discourse) and authenticated user name (root) do not match
2021-04-01 18:44:16.544 UTC [1155] discourse@discourse FATAL:  Peer authentication failed for user "discourse"
2021-04-01 18:44:16.544 UTC [1155] discourse@discourse DETAIL:  Connection matched pg_hba.conf line 94: "local   all             all                                     peer"
2021-04-02 03:33:33.893 UTC [36640] discourse@discourse LOG:  duration: 141.998 ms  statement: COPY public.stylesheet_cache (id, target, digest, content, created_at, updated_at, theme_id, source_map) TO stdout;
2021-04-02 17:49:50.676 UTC [92100] discourse@discourse LOG:  duration: 156.461 ms  statement: DO $$DECLARE row record;
        BEGIN
          -- create <destination> schema if it does not exists already
          -- NOTE: DROP & CREATE SCHEMA is easier, but we don't want to drop the public schema
          -- otherwise extensions (like hstore & pg_trgm) won't work anymore...
          CREATE SCHEMA IF NOT EXISTS backup;
          -- move all <source> tables to <destination> schema
          FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'public'  AND tableowner = 'discourse'
          LOOP
            EXECUTE 'DROP TABLE IF EXISTS backup.' || quote_ident(row.tablename) || ' CASCADE;';
            EXECUTE 'ALTER TABLE public.' || quote_ident(row.tablename) || ' SET SCHEMA backup;';
          END LOOP;
          -- move all <source> views to <destination> schema
          FOR row IN SELECT viewname FROM pg_views WHERE schemaname = 'public' AND viewowner = 'discourse'
          LOOP
            EXECUTE 'DROP VIEW IF EXISTS backup.' || quote_ident(row.viewname) || ' CASCADE;';
            EXECUTE 'ALTER VIEW public.' || quote_ident(row.viewname) || ' SET SCHEMA backup;';
          END LOOP;
        END$$;

2021-04-02 17:49:52.092 UTC [92128] discourse@discourse LOG:  duration: 114.918 ms  statement: COPY public.scheduler_stats (id, name, hostname, pid, duration_ms, live_slots_start, live_slots_finish, started_at, success, error) FROM stdin;
2021-04-02 17:49:53.398 UTC [92128] discourse@discourse LOG:  duration: 1266.208 ms  statement: COPY public.stylesheet_cache (id, target, digest, content, created_at, updated_at, theme_id, source_map) FROM stdin;
2021-04-02 17:51:24.451 UTC [51] LOG:  received smart shutdown request
2021-04-02 17:51:26.828 UTC [51] LOG:  background worker "logical replication launcher" (PID 79) exited with exit code 1
2021-04-02 17:51:26.836 UTC [74] LOG:  shutting down
2021-04-02 17:51:26.948 UTC [51] LOG:  database system is shut down
2021-04-02 18:00:56.877 UTC [52] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-02 18:00:56.879 UTC [52] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-04-02 18:00:56.879 UTC [52] LOG:  listening on IPv6 address "::", port 5432
2021-04-02 18:00:56.880 UTC [52] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-02 18:00:56.893 UTC [73] LOG:  database system was shut down at 2021-04-02 18:00:11 UTC
2021-04-02 18:00:56.909 UTC [52] LOG:  database system is ready to accept connections
2021-04-02 18:03:23.275 UTC [343] discourse@discourse LOG:  duration: 172.267 ms  statement: UPDATE "stylesheet_cache"
           SET "content" = REPLACE("content", '/uploads', '/../uploads'), "digest" = REPLACE("digest", '/uploads', '/../uploads'), "source_map" = REPLACE("source_map", '/uploads', '/../uploads'), "target" = REPLACE("target", '/uploads', '/../uploads')
         WHERE "content" IS NOT NULL AND "content" LIKE '%/uploads%' OR "digest" IS NOT NULL AND "digest" LIKE '%/uploads%' OR "source_map" IS NOT NULL AND "source_map" LIKE '%/uploads%' OR "target" IS NOT NULL AND "target" LIKE '%/uploads%'

2021-04-02 18:03:55.952 UTC [52] LOG:  received smart shutdown request
2021-04-02 18:03:57.185 UTC [52] LOG:  background worker "logical replication launcher" (PID 79) exited with exit code 1
2021-04-02 18:03:57.189 UTC [74] LOG:  shutting down
2021-04-02 18:03:57.308 UTC [52] LOG:  database system is shut down
2021-04-02 18:04:00.354 UTC [47] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-02 18:04:00.355 UTC [47] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-04-02 18:04:00.356 UTC [47] LOG:  listening on IPv6 address "::", port 5432
2021-04-02 18:04:00.359 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-02 18:04:00.375 UTC [66] LOG:  database system was shut down at 2021-04-02 18:03:57 UTC
2021-04-02 18:04:00.380 UTC [47] LOG:  database system is ready to accept connections
2021-04-02 18:13:27.137 UTC [47] LOG:  received smart shutdown request
2021-04-02 18:13:27.980 UTC [47] LOG:  background worker "logical replication launcher" (PID 72) exited with exit code 1
2021-04-02 18:13:27.982 UTC [67] LOG:  shutting down
2021-04-02 18:13:28.009 UTC [47] LOG:  database system is shut down
2021-04-02 18:13:31.497 UTC [45] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-02 18:13:31.499 UTC [45] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-04-02 18:13:31.499 UTC [45] LOG:  listening on IPv6 address "::", port 5432
2021-04-02 18:13:31.500 UTC [45] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-02 18:13:31.515 UTC [67] LOG:  database system was shut down at 2021-04-02 18:13:27 UTC
2021-04-02 18:13:31.520 UTC [45] LOG:  database system is ready to accept connections

Nginx error log

2021/04/02 18:01:06 [error] 69#69: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: _, request: "GET /ask/ HTTP/1.0", upstream: "http://127.0.0.1:3000/ask/", host: "localhost:1357"
2021/04/02 18:13:38 [error] 64#64: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: _, request: "POST /ask/message-bus/c734a550b6e54923aff3e0c6fdf1b014/poll HTTP/1.0", upstream: "http://127.0.0.1:3000/ask/message-bus/c734a550b6e54923aff3e0c6fdf1b014/poll", host: "localhost:1357", referrer: "https://privitevps.ga/ask/latest"

When do you need it done?

ASAP

What is your budget, in $ USD that you can offer for this task?

Open to suggestions. Please PM me with your approach and estimate.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.