Nginx as a proxy on top of Discourse Docker container


(John Arce) #1

I’m using discourse at http://webgeek.ph (previous wordpress)

So now I want to preserve some of my previous pages from wordpress and create some html pages on discourse.(example: webgeek.ph/about.html) and rewrite .html to webgeek.ph/about

Is it possible to setup an nginx config to proxy my discourse install?

Can anyone help me write an nginx configuration for this? I’ve been trying this for a week and still no luck.


(Jeff Atwood) #2

Did you search for the terms “nginx docker” here without the quotes? There are quite a few matches that might be of interest to you…


(Arpit Jalan) #3

This may help you:


(John Arce) #4

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

but I still need to set the location path so I can upload html files to /var/www/webgeek.ph/htdocs

My config:

  upstream discourse {
  #fail_timeout is optional; I throw it in to see errors quickly
   server 127.0.0.1:4578 fail_timeout=5;
  }


  # configure the virtual host
  server {
    # replace with your domain name
    server_name webgeek.ph;

    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;

    }
  }

How can I add something like this? root /var/www/webgeek.ph/htdocs;


(John Arce) #5

Finally! It’s working now.

I want to share my config based from @trident post and I added some rewrite rules.

preview here: http://webgeek.ph (discourse)
static html page with rewrite: http://webgeek.ph/devcup-2014/

upstream discourse {
#fail_timeout is optional; I throw it in to see errors quickly
  server 127.0.0.1:4578 fail_timeout=5;
}


# configure the virtual host
server {
  # replace with your domain name
  server_name webgeek.ph;
  
  root /var/www/webgeek.ph/htdocs;
  index index.html;
  
  #Rewrite

  # assets
  location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|txt|css|js) {
    try_files $uri @discourse;
    add_header Cache-Control public;
    add_header Cache-Control must-revalidate;
    expires 7d;
  }

  # example.com/a.html gets redirected to example.com/a
  location ~* \.html$ {
    rewrite ^(.*)\/index.html$ $1 permanent;
    rewrite ^(.+)\.html$ $scheme://$host$1 permanent;
  }
  
  # example.com/foo/ loads example.com/foo/index.html
  location ~* ^(.*)/$ {
    try_files $1.html $1/index.html @discourse;
  }
  
  # anything else not processed by the above rules:
  # * example.com/a will load example.com/a.html
  # * or if that fails, example.com/a/index.html
  
  location / {
    rewrite ^(.*)\/index$ $1 permanent;
    try_files $uri.html $uri/index.html @discourse;
  }
  
  location @discourse {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://discourse;
  }

}