Run Discourse with or alongside existing Apache sites?


#1

Hi all,

So I have a numerous web apps running under Apache on my Arch Linux server. Installing Discourse with Docker according to installation guide leaves Discourse “overtaking” my apache sites as anything directed to the server IP on port 80 is directed to Discourse.

I am comfortable with Apache, but never used Docker before so any advise or help anyone could provide would be most welcome. I am very excited about giving Discourse a whirl.

Cheers!


All users have the same IP (the Servers IP)?
How to install discourse on hosting?
Discourse not showing up at specified hostname
Domain names pointing with shared AWS instance
(Carlo Kok) #2

just setup a virtual host for discourse.


#3

Care to elaborate how?

Ive tried a few examples found here on the forums without any luck.

<VirtualHost *:80>
ServerAdmin ...
ServerName ....
DocumentRoot /usr/share/webapps/androidforum/public
UserDir disabled
DirectoryIndex disabled

<Directory "/usr/share/webapps/androidforum/public">
    AllowOverride None
    Require all granted
</Directory>

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://127.0.0.1:3111%{REQUEST_URI} [P,QSA,L]

Im guessing I would still need to start the Discourse with launcher.


(Ben T) #4

You can try to follow the steps outlined here to set up a nginx install in front of your various sites.


#5

Hmm, seems a bit cumbersome to run Docker, Apache and an extra NGIX proxy. Is there no easier way?


#6

Wouldnt something like this potentially work?

<VirtualHost *:80>
    ServerAdmin ...
    ServerName ...

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    ErrorLog /var/log/httpd/forum_error.log
    CustomLog /var/log/httpd/forum_access.log combined
</VirtualHost>

Limiting/forcing single hostname in a setup alongside multiple (Apache served) sites
(Kane York) #7

Yes, but long polling will be broken - you’ll have to adjust some site settings to enable the workaround.


#8

Ah I see. Any documentation on what settings need tobe adjusted to make it work?

So there is no simple option here to run Discourse along side my existing Apache infrastructure?


(Kane York) #9

No, what you posted will work - it’s just that notifications will lag behind by ~7 seconds.


#10

Ah OK, cool! However its not working at the moment but I’m guessing I am to blame there.

I guess I need to adjust app.yaml so that it listens on a different port than port 80? I tried but it didn’t seem to have any effect.

Sorry for all the questions but just really eager to play with Discourse :slight_smile:


(Jens Maier) #11

I have this setup:

<Proxy balancer://unicorns>
    BalancerMember http://127.0.0.1:4000
</Proxy>

<VirtualHost *:80>
    ServerName my.example.com
    CustomLog logs/sites/my.example.com/access_log combined
    ErrorLog logs/sites/my.example.com/error_log
    ServerAdmin me@example.com

    DocumentRoot /var/www/my.example.com/htdocs
    UserDir disabled
    DirectoryIndex disabled

    <Directory "/var/www/my.example.com/htdocs">
        AllowOverride All
        Options -MultiViews
        Require all granted
    </Directory>

    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://unicorns%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

The directory /var/www/my.example.com/htdocs is just a symlink to Discourse’s public directory and my Apache 2.4 uses the evented MPM.

So far, this works reliably and stable for a forum with around a dozen users, so I can’t make any claims that its battle tested – but I don’t think I’ve noticed problems with long polling.

By the way, I’m using the internal redirect via mod_rewrite because in my actual configuration, I’m also merging an OwnCloud installation into the directory tree… :wink:


Can't make Discourse accessible through Apache
403 forbidden after installation
(Sam Saffron) #12

Set up haproxy , nginx or varnish in front and farm port 80 to the correct children

Don’t use apache mod proxy, strongly not recommended.

Discourse expects long polling to work, apache has a very low concurrent connection count. Long polling will break and potentially cause your users to DoS themselves.


#13

Hmm, is there no way to configure Discourse to work better without long polling support?


(Sof) #14

This is my website.com.conf apache2 file :

<VirtualHost *:80>

        ServerName www.website.com
        ServerAdmin webmaster@website.com

        ServerAlias website.com www.website.com
        DocumentRoot /home/user/www/website.com

        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /home/user/www/website.com>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/website.com.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/website.com.access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

<VirtualHost *:80>

        ServerName forum.website.com
        ServerAdmin webmaster@website.com

#       ServerAlias forums.website.com forum.website.com
        DocumentRoot /home/user/www/website.com/forums 

        ProxyPreserveHost On
        ProxyRequests Off

        ProxyPass / http://localhost:4578/
        ProxyPassReverse / http://localhost:4578/

        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /home/user/www/website.com/forums>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/forum.website.com.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/forum.website.com.access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Don’t forget to configure app.yml file :

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

Restart apache.

It works for me.


#15

And you need to start Discourse with launcher as well, right?


(Jens Maier) #16

Can I get some numbers?

I’m running my Discourse forum out of my wimpy, old basement server with an Athlon64 X2 4200+, mix’n’matched DDR modules worth 3 GB in total and an old WD Raptor HDD. Despite hardware almost a decade old, Apache with the event MPM and some mild tuning (AsyncRequestWorkerFactor 12) handles 1000 concurrent connections to /message-bus/xyz/poll? easily.

(I am getting some errors because processes keep running out of file handles; ulimit -n is set to a system default of 1024. Also, I’m getting errors when attempting this with SSL; apparently, my /dev/urandom is running out of entropy.)


(Sof) #17

Right !
You start discourse normally. It will start listening on its own port.
Apache will run normally serving other websites.


#18

Thanks all. Got it working. I realize though that its far from an ideal setup, so hopefully Ill be able to work out a better solution before putting this into production.


(Robert Jan De Dreu) #19

What I did is just add a different IP to my server and made Apache ignore that one. After doing so I bound discourse to that IP.


(Sam Saffron) #20

My bigger concern here is people going with default non evented apache, cause they are totally hosed.

If you can do 1000 concurrent you should be fine.


Apache webserver already running