Success - New Multisite Install on Dedicated server using ServerPilot, Nginx and Apache

Here’s what I did to install a successful installation of Discourse for multiple instances on a dedicated server that uses Nginx and Apache.

I decided to create a new topic since my installation seems to be a little unique from what I have seen others having to go through. I am very new to Nginx webservers and thought this might help others who may be struggling to connect the dots. I’m also at a beginner level when it comes to using the terminal to access my server, I still have to look up commands for most of the stuff I want to do, but I am finding it so much faster and powerful vs FTP. I still use FTP for a visual representation to locate files and text editing (I don’t like vi or nano editing in the terminal) I use Coda (on a Mac) as my text editor so I have direct access to the server. Which means I can live edit my files just as one would do in the terminal.

I’m using ServerPilot as the control panel to manage my websites on an Ubuntu 14.04 installation. ServerPilot uses Nginx as a reverse proxy in front of the Apache webserver. At first I was a bit confused with this, and basically what they have done is use Nginx as the hub where website requests come into the Nginx server and get routed to Apache to be executed and then back through Nginx to be displayed. This proved to cause some trouble with my installation as I had to figure out where all the config files and such were located.

I started with this tutorial for installing the first instance of Discourse as a dev version …

https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md

Pay special attention to the TCP/IP ports as that was the first place I stumbled, and I see a lot of other posts in the forums from other people who have done the same. If you leave them at the default “80:80” you may get an error stating that port is already in use.

Change the first half of the ports to a port that is not being used, I used 85

This got me through the installation with no errors, but when I went to the url I setup for the forum nothing was showing up. I could connect to the forum using the IP with the port number. Since the forum doesn’t need Apache, I found the conf file that was directing the site to the Apache server with a local IP. I changed this IP to the forum IP with port number.

The path to that section (if you’re also using ServerPilot)

/etc/nginx-sp/vhosts.d/main.conf
(ServerPilot recommends that you change the name of the main.conf file so it is not overwritten on updates)

Now I had a working instance of Discourse, and here’s what I did to set up the multiple instances.

I started with this tutorial, but I was having trouble understanding how the structure was supposed to be setup

If you scroll down to this section …

https://meta.discourse.org/t/multisite-configuration-with-docker/14084/18

This is where I based my installation from, however I did not use the hook settings in the original post. Instead, I duplicated the app.yml file for each site I was creating (only two sites) and renamed them for site specific use. I’ll use the example - site1 and site2.

So in the /var/discourse/containers the files there are as such …

app.yml
site1.yml
site2.yml

(these are your separate containers, which was a term that I didn’t understand at first)

For each file you need to make sure to change the following areas to be specific to your instance …

## which TCP/IP ports should this container expose?
expose:
  - "127.0.0.1:4000:80"   # fwd host port 80   to container port 80 (http)
  - "2222:22" # fwd host port 2222 to container port 22 (ssh)

Notice I changed the first port on both, otherwise you will get port conflict errors.

  ## 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: 'changeme@site1.com'

change the developer email to the email you will use for the admin account

In the mailserver section that follows, be sure to change any settings that are specific to this site such as the username and password. I ended up using Mandrill so the smtp and port numbers were the same for all instances, but I created two accounts. (one for each website)

This next section to edit is key to you getting a separate database for each site. Be sure to change the ‘yoursite’ to something unique to each site.

## These containers are stateless, all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/yoursite
      guest: /shared
  - volume:
      host: /var/discourse/shared/yoursite/log/var-log
      guest: /var/log

The next thing to do is make sure you have the Nginx proxy URL (the one that is pointing to Apache) changed to match the port you configured in the TCP/IP section. So using the port I used as an example your file should look like this and as I mentioned above, ServerPilot recommends changing the name of the file if you MUST edit (that’s why they give the do not edit warning)

###############################################################################
# DO NOT EDIT THIS FILE.
#
# Your changes to this file will be overwritten by ServerPilot.
#
# For information on how to customize nginx settings, see
# https://serverpilot.io/community/articles/customize-nginx-settings.html
###############################################################################

# Send all requests to apache.
location / {
    proxy_pass      http://localhost:4000;

Be sure to restart Nginx if you make changes to the .conf file (I forgot to do this) and with ServerPilot the restart command is a little different than I had seen elsewhere, this is what did it for me …

service nginx-sp restart

Then start bootstrapping your containers. (do this for each site your configured) Enter these commands in the terminal

./launcher bootstrap site1
(after that is done)
./launcher start site1

You should now be able to load the URL you have for the forum and see your Discourse forum.

I ended up with one of the sites not recognizing the Admin account when I registered with the developer email, and I found I had a stray character at the end of the URL that caused the email to be different. I then went into the /var/discourse/shared/ directory and deleted the folder matching that site. Then I used ./launcher destroy site2 command followed by ./launcher bootstrap site2 and then ./launcher start site2 I’m not sure a rebuild would work since you want the database to be recreated.

I know I probably over-simplified this is some areas, but from what I have seen in other topics/threads, some people need instructions that are overly simplified :wink:

Please let me know if I left any holes, or there is any need for clarification as long as you understand I can only speak for what worked for me since I barely understand this myself HA!!!

One more thing … does any one see any issue with duplicating the app.yml file to be used in this way? It seems this would work perfectly for updating as well.

Best regards … Pops

9 « J'aime »

Actually, ports <1024 are considered “privileged”, using them without assignment is… not technically wrong, but ugly. Also, you should bind Discourse to the local interface:

expose:
  - "127.0.0.1:4000:80"

Change your nginx config accordingly to proxy_pass http://localhost:4000;

Overall, nice write-up, but do turn your YAML and other config file snippets into proper fenced code blocks (``` on a line by itself before and after the code block). Especially for YAML, indentation is really important and it gets lost in simple quote blocks. :wink:

1 « J'aime »

That makes complete sense, I made the changes suggested to my server and they work perfectly. I also changed them in the above instructions as well as used the code markdown instead of the quote markdown (thanks for pointing that out)

… Pops

1 « J'aime »

@elberet hmmm, something isn’t quite right when changing the ports on the production sites

Changing the ports as you suggested on the app.yml file worked great, but after changing the two additional container files with the appropriate changes I get a 502 bad gateway error.

I made the changes to the exposed port, as well as the proxy_pass, I then rebuilt the the instance using ./launcher rebuild as well as restarted the Nginx server.

Any idea what’s wrong?

… Pops

EDIT: very weird … I was issuing the restart command for Nginx, but when I stopped it, and then started instead of “restart” everything is working fine

You can also stop exporting ports entirely by using web.socketed.template.yml:

4 « J'aime »

I saw that post, but had a difficult time understanding how to implement it in the way my server is set up since Nginx is already installed and running in front of Apache.

It had to do with the last step, the path you referenced for sites-enabled an sites-available doesn’t exist and if I just needed to create them, I didn’t know how the files as a whole were to be set. (just a lack of knowledge on my part)

@PopsRocker Hi Pops!

Like you I’m trying to set up Discourse on DigitalOcean with ServerPilot, already running another website in a ServerPilot app (app named ‘test’). I only need a single Discourse site, so my setup will be simpler than yours.

Along with app#1 (test) hosting a website, I’ve got a 2nd ServerPilot app (named ‘discourse’) set up for purposes of pointing to the Discourse install. This gives me the /etc/nginx-sp/vhosts.d/discourse.conf and /etc/nginx-sp/vhosts.d/discourse.d/main.conf files.

So my question: what modifications did you make to your .conf files to get it to forward requests to discourse? I’ve got Discourse running and can access it from discourse.example.com:8888. What is it I need to do in the nginx conf files so that I can see Discourse at discourse.example.com, without appending the port number?

Thx

Sorry, replied too soon and then found my answer above:

in app.yml:

expose:
  - "127.0.0.1:8888:80" # fwd host port 80 to container port 8888 (http)
  - "2222:22" # fwd host port 22 to container port 2222 (ssh)

in /etc/nginx-sp/vhosts.d/discourse.d/main.conf (renamed to main.custom.conf as suggested):

location / {
    proxy_pass $backend_protocol://$backend_host:8888;
}

I’m still a little confused with this Serverpilot / Discourse setup. When you created your “discourse” app in Serverpilot, what did you put in the apps/discourse/public/ directory? I have my current discourse installation in the /var/discourse directory but am not sure how Serverpilot is suppose to recognize that?

You don’t actually have to put anything in the apps/discourse/public/ directory. Instead, you want requests to that Serverpilot app forwarded to your Discourse install living in /var/.

This is accomplished via the /var/discourse/containers/app.yml and /etc/nginx-sp/vhosts.d/discourse.d/main.custom.conf modifications referenced in my previous post.

1 « J'aime »

Thanks for your help! I was able to get it up and running.

I’m using ServerPilot too. Glad I found this article. I will let you know, how it’s worked up for me.
Thank you.

Thanks for the info on this. I know it has been a while, does anyone happen to know what kind of increase in resources on the system end up being consumed when you have a second one?

Maybe it’s because this post is from 2015 … but now I can not find the nginx-sp directory in my installation (I did it with the docker automatically).

I have all the second.yml completely changed, but I don’t know where it’s the nginx file to do the proxy thing.

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Ce chemin ne devrait-il pas contenir /standalone/ pour le premier site, non ?

Je me demande s’il n’y a pas une confusion entre multisite et WP+Discourse dans une configuration à deux conteneurs ? :face_with_raised_eyebrow:

Nous exécutons facilement plusieurs applications Discourse (sur le même serveur) avec un conteneur pour les données et un conteneur pour l’application, pour chaque « instance de domaine » que nous exécutons.

De plus, pour chaque « instance de domaine », nous exécutons deux conteneurs d’applications. Cela signifie qu’il n’y a aucun temps d’arrêt lorsque nous reconstruisons un conteneur.

Pourquoi ?

Parce que lorsque le « conteneur A » est en cours d’exécution, nous reconstruisons le « conteneur B » ; et une fois que le « conteneur B » a été reconstruit, nous attendons environ 1 minute, puis nous reconfigurons le proxy inverse pour qu’il se connecte au socket Unix du « conteneur B » et nous exécutons (dans le cas d’apache2) service apache2 restart.

Cela signifie qu’il n’y a pratiquement aucun temps d’arrêt (peut-être quelques millisecondes) lors du passage d’un conteneur à l’autre.

Je suis à suivre ce fil avec admiration, face à la difficulté (ou la complexité) avec laquelle beaucoup de gens rendent quelque chose qui est fondamentalement très simple.

Discourse en production s’exécute dans un conteneur Docker ; et la bonne équipe de Discourse a fourni les modèles de base pour exposer Discourse soit via un socket TCP/IP, soit via un socket de domaine Unix (par instance d’application). De plus, la bonne équipe de meta a fourni le modèle de base pour exécuter le conteneur de données (PostgreSQL) séparément du conteneur d’application (Rails, JS).

Le même concept s’applique à n’importe quelle application Node.js exécutée dans un conteneur. Ces configurations (proxys inverses vers des conteneurs) sont des tâches Docker de base qui s’appliquent à toutes les applications Web exécutées dans un conteneur. Discourse est simplement l’une d’entre elles, et l’une des meilleures comme nous le savons tous :slight_smile:

Parfois, je pense que l’excellente équipe de meta Discourse rend si facile le lancement de leur conteneur avec leurs scripts d’encapsulation bien conçus, que les utilisateurs ne comprennent pas que les fondamentaux sous-jacents de l’exécution d’une application Web basée sur Docker derrière un proxy inverse sont en réalité assez simples.

Nous pouvons exécuter « autant d’applications Discourse » que nous le souhaitons, en tant que hôtes virtuels, sans différence avec un administrateur web qui exécuterait 20 « anciennes applications Web LAMP » sur le même serveur. La seule différence est qu’au lieu d’un hôte virtuel pointant vers un répertoire de fichiers PHP, il y a un hôte virtuel pointant vers (dans notre cas) un socket de domaine Unix. Docker rend cela très efficace en partageant les bibliothèques de base et les calques entre les conteneurs !

De plus, comme la mise en réseau entre les conteneurs est intégrée à Docker, il est très facile de configurer Discourse (en tant que conteneur d’application) pour qu’il fonctionne avec un conteneur PostgreSQL (données) ; ce qui est fourni à tous les utilisateurs comme modèle de base par la bonne équipe de meta, pour ceux qui souhaitent exécuter Discourse de manières plus « intéressantes » (configurations).

Mon conseil, pour ce qu’il vaut, est de comprendre que Discourse est simplement une application Web exécutée dans un conteneur derrière un proxy inverse, comme n’importe quelle application Web. Nous exécutons également notre registre Docker privé (plus d’un en fait) de la même manière ; une application Docker derrière le même proxy inverse sur le port 5000 (le port par défaut du registre Docker).

Discourse, dans sa sagesse pour rendre la vie facile aux utilisateurs (et rendre Discourse accessible aux non-experts en administration système), fournit la possibilité d’exposer directement les applications Web (sans proxy inverse) dans leur configuration par défaut (OOTB). De plus, la configuration d’un proxy inverse en dehors du conteneur Docker est la même pour toutes ces applications Web conteneurisées. L’équipe de meta fournit également ces modèles (un tel soutien si vous y réfléchissez !).

Pour conclure, il est très facile d’exécuter une, vingt ou plus d’applications conteneurisées derrière un proxy inverse. Ce ne sont que des conteneurs (et tous pourraient être un forum Discourse différent), et le choix de la façon d’exposer les conteneurs revient à l’utilisateur (l’administrateur système), tout comme les choix de configuration des volumes de stockage persistants, y compris les bases de données.

Je pense que c’est si simple et que l’équipe de meta l’a rendu si simple pour tout le monde ; mais l’un des effets secondaires de cette simplicité est que les gens ont oublié (ou n’ont pas appris) les fondamentaux de la facilité et de l’élégance de la configuration conteneurisée (derrière un proxy inverse) en réalité (indépendamment de Discourse).

J’espère que cela aidera d’une petite manière.

Meilleures salutations !

7 « J'aime »

C’est vraiment simple…

Chaque application possède son propre volume partagé, et c’est dans ce volume que le socket de domaine Unix s’exécute (ainsi que toutes les autres données persistantes comme les téléchargements, etc.).

Vous n’avez pas besoin de travailler directement avec docker-compose, de directives pup spéciales, ou de modifier quoi que ce soit (il suffit de configurer correctement les fichiers yml de base pour les conteneurs et d’exécuter le launcher).

Si l’un de vos sites/applications Discourse s’appelle « farmer_forums », alors votre socket Unix se trouve (par défaut), par exemple :

/var/discourse/shared/farmer_forums/nginx.http.socket

Si votre prochain site/application Discourse s’appelle « race_car_forums », alors votre socket Unix se trouve (par exemple) ici :

/var/discourse/shared/race_car_forums/nginx.http.socket

Vous pouvez le faire pour des centaines de forums, si vous le souhaitez ; et chacun n’est qu’une entrée dans un proxy inversé pointant vers ce socket. Nommez simplement vos fichiers yml de conteneurs de manière appropriée.

Chacun de ces forums aura également son propre conteneur de données. Vous pouvez utiliser n’importe quelle convention de nommage pour ces conteneurs, par exemple :

  • farmer_forums_data
  • race_car_forums_data

Bien sûr, chacun d’eux aura son propre volume partagé pour sa(ses) base(s) de données.

Tout ce que vous avez à faire est de créer une solution fonctionnelle à « deux conteneurs » et de la répliquer derrière un proxy inversé. Créer un site, ou 100 sites, c’est exactement la même chose si vous suivez cette méthode simple.

PS : J’ai entendu (lu) que certaines personnes essaient d’utiliser un seul conteneur de base de données pour plusieurs forums différents. Je ne le recommanderais jamais personnellement. Cette configuration crée un point de défaillance unique pour tous les forums et ce n’est pas ainsi que j’aime procéder : « keep it simple and stupid » (KISS). Mais j’aime KISS en administration système, car j’ai commis des erreurs de frappe au fil des décennies plus d’une fois :slight_smile: et donc je n’aime pas casser plus que nécessaire quand je fais une erreur (ce que nous faisons tous, de temps en temps).

Donc, si vous avez des difficultés avec cela : commencez par mettre en place un seul site avec deux conteneurs, l’application et le conteneur de données, derrière un proxy inversé.

Ensuite, répliquez-le autant de fois que vous le souhaitez, avec un conteneur d’application et un conteneur de données pour chaque site. Tous vos noms de conteneurs doivent être uniques et doivent suivre une convention de nommage facile à retenir, comme dans les exemples des fermes et des voitures de course ci-dessus.

Je ne cherche pas à paraître répétitif ni moralisateur, mais il est presque trivial de configurer de nombreux sites Discourse derrière un proxy inversé de cette manière.

J’espère que cette explication supplémentaire vous aidera, ne serait-ce que légèrement.

En résumé, pour moi, « multisite » signifie simplement mettre en œuvre la solution « deux conteneurs » derrière un proxy inversé, plusieurs fois, autant de fois que vous le souhaitez ! :slight_smile: Un ou dix, c’est fondamentalement la même configuration ; seuls les noms des conteneurs diffèrent, et il existe une configuration de nommage de conteneurs « facile à comprendre » (comme dans les deux exemples ci-dessus). Docker partagera les bibliothèques et les overlays de manière appropriée entre les images, donc il n’y a « rien à faire ici » car « c’est ce que Docker fait » (configure toutes les bibliothèques partagées, construit le réseau Docker, etc.) tout seul, ce qui rend cela « efficace » grâce à la façon dont Docker partage les bibliothèques entre les images, etc.

8 « J'aime »

Peut-être devrions-nous appeler cette configuration autre chose que multisite (qui, selon moi, partage le conteneur de données, cf. le sujet du tutoriel fermé par Sam l’année dernière)
Site parallèle ? :crazy_face: je ne sais pas…
Si je ne me trompe pas, puisque vous avez un fichier .yml par couple de conteneurs données/web, pouvez-vous spécifier différents ensembles de plugins et SMTP par domaine ?

1 « J'aime »