Using nginx alongside the Docker install


(Matthew Burgos) #1

I am currently running nginx on my droplet, will these instructions play nice with what I already have configured?


(Ben T) #2

This install guide will bind to port 80; which nginx is already bound to. You’ll have to set up forwarding between your nginx install and the docker container.


(Matthew Burgos) #3

Do you have an example of what that might look like in the nginx sites-enabled configuration file? Or is that not even the proper place to forward?

And would I then be able to start up discourse using the ./launcher start app command?


(Ben T) #4

You would have to change the port the docker container binds to in app.yml to something other than 80; and then in your nginx install set up http forwarding to direct to this alternate port. Follow the steps for installing normally until you reach ./launcher bootstrap app

  • Edit app.yml to bind to a port other than port 80 externally. Pick something that is not in use (maybe 4578?)
 - "4578:80"   # fwd host port 4578   to container port 80 (http)
  • Continue with the steps above (bootstraping, starting), and verify that you can see discourse on the alternate port. Use your server IP as above, and add in the port you chose. For example: http://8.8.8.8:4578 if your server IP was 8.8.8.8.

  • Configure your current nginx install to proxy_pass to the docker container. Here is an example of something you can include in sites-enabled.

  • Remember to restart your external nginx.

A cool thing you can do is forward between two different servers this way. So, if you’re just trying out discourse… you could configure your current production server to forward to a new droplet/vps and try out some features.


Nginx as a proxy on top of Discourse Docker container
Can I use Discourse in a LAMP Server Stack?
Hosting other Ruby on Rails App Side by Side with Discourse
(Matthew Burgos) #5

Thank you. That is exactly what I was hoping for.

edit:
Now getting an error on these lines in the nginx configuration:

location / {
  try_files @app;
}

edit also i still cant start up the app because it still says that port 80 is already bound. Hmmm.


(Ben T) #6

What error exactly from nginx? It’s possible I made a mistake in my config file… I’ve gone back and tried to simplify it a little more.

Is the docker container saying that port 80 is already bound? Make sure you are destroying and then bootstraping when making changes to app.yml. I had assumed you were doing a new install.


(Matthew Burgos) #7
2014/05/03 11:46:21 [emerg] 22743#0: invalid number of arguments in "try_files" directive in /etc/nginx/sites-enabled/discourse.mydomain.net:12

I figured out to rebuild and now i can actually reach it by typing in the address with the port, but when i try to restart gninx i get the above error.

btw i have more than one enabled site within the nginx sites-enabled folder.


(Ben T) #8

Okay; that must have been my mistake with the file I linked and try_files. I’ve updated it to fix that issue; so it should be all set now.


(Matthew Burgos) #9

YES! That worked! Thanks man!


(John Arce) #10

@trident

I followed your instruction.

Port is working now at http://webgeek.ph:4578/

How can I set the path so I can upload html? example to root /var/www/webgeek.ph/htdocs


(Ben T) #11

It will be much easier if you set up a subdomain. Create another config file with a different server_name. This will be much easier. You would then create another A record pointing to the same IP, and handle requests that way.

You can always add another location block; which can handle subfolders. You’d then have to re-write requests within that block, and make sure to not cover over any discourse routes.


(John Arce) #12

@trident Yes thats my initial plan but I already decided to discourse as homepage.


(Librae) #13

It’s working nicely. Thank you @trident


(liwei_swjtu) #14

@trident I followed your steps but still with bad luck.
Here’s my discourse.conf file like:

upstream discourse {
  server 127.0.0.1:8080 fail_timeout=5;
  }

server {

  server_name bbs.dushu.ba

  location / {
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    proxy_redirect off;

    proxy_pass http://discourse;

  }

}

Is there anything else I should notice? Thank you.


(Ben T) #15

Can you reach discourse at (your URL):8080?


(liwei_swjtu) #16

Yes,I can reach at myURL:8080


(Ben T) #17

What happens if you run these commands as root:

service nginx stop
nginx

(liwei_swjtu) #18

I just tried, after stop the nginx service,it can’t start it again unless I remove the discourse.conf


(Ben T) #19

It should specify where the error is in the discourse.conf file when you run it from the console. Can you post a copy that is not formatted/in code blocks? Like this.


(liwei_swjtu) #20

My discousre.conf file is like this:

upstream discourse {
server 127.0.0.1:8080 fail_timeout=5;
}

server {

server_name bbs.dushu.ba

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

proxy_pass http://discourse;
}

}