Having discourse under apache reverse proxy


(Jakub Ryška) #1

I have installed discourse docker on my server and it is bound to port :8880. When I access it in browser on that port like http://myserver:8880, it works fine. But I don’t want to bind the real world app to that port, but use standart 80. So I tried to put the server under apache reverse-proxy. Here is the immortant part of discourse.conf.

ServerName myserver

ProxyPass / http://localhost:8880/
ProxyPassReverse / http://localhost:8880/

It works, but with a major glitch, every request is recognized as it was from mobile device, I see this style linked:

<link href="/uploads/stylesheet-cache/mobile_df9856b3a498598d8339e91059a01f122f64728b.css" media="screen" rel="stylesheet" />

When I access the server directly via :8880, then I see the expected desktop style:

<link href="/uploads/stylesheet-cache/desktop_df9856b3a498598d8339e91059a01f122f64728b.css" media="screen" rel="stylesheet" />

Do you know, what should I alter in order to make it work correcly, recognize desktop device as desktop and not as mobile one?


(Jeff Atwood) #2

I am guessing the User-Agent string is not being passed through?


(Jakub Ryška) #3

No, the User-Agent is propagated through the proxy, i can see it by dumping the tcp.

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36

(Kane York) #4

As a note, I think you are going to need to disable long polling in the “Developer” site settings, as it is not supported by Apache.


(Jakub Ryška) #5

Thanks for the note. It didn’t solve the problem though. I suppose you didn’t expect it to solve the problem anyway :slight_smile:


(Sam Saffron) #6

Mobile detection is all user agent based, try adding ?pp=env to the end of a URL as admin to have a look at headers.

I also strongly recommend NGINX for Discourse or even better our Docker setup that solve all these issues, we do not test at all on apache and giving up long polling is a big price to pay.


(Jakub Ryška) #7

Yeah, by appending this ?pp=env, I can see that the user agent indication is the same as with the tcpdump.

HTTP_USER_AGENT: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36

Ok, I won’t put the discourse under apache, but I still need some server upfront if I want to host more sites than just the discourse on :80 port, I have the docker installation and I need to forward requests there because the docker is bound to non-80 port.


(Ben T) #8

You can configure nginx with multiple server blocks; then internally forward requests. You’d have to change all of your apache config files to nginx config files; but the concept is the same.