I have spent some time setting up nginx as a reverse proxy for vibe, and I thought I might share some of my issues here for now, just in case it helps someone.

I will assume that you are generally familiar with configuring nginx, where the files are, how server directives work etc.

The basic setup is the same as any other reverse proxy:

   server {
      listen 80;
      server_name dev.mysite.com;

      location / {
         proxy_pass http://localhost:8080/;
         proxy_redirect off;

         proxy_http_version 1.1;

         proxy_set_header   Host     $host;
         proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header   Content-Length   $body_bytes_sent;
      }
   }

The important things to note are that you need nginx version 1.1.4 at least. Vibe doesn't seem to work correctly with HTTP 1.0 requests in this configuration. Also, the line `proxy_set_header Content-Length $body_bytes_sent;` is necessary because vibe will wait for a body, for some reason when being proxied, this results in both nginx and vibe waiting for each other, with nginx eventually timing out. The Content-Length line sets the correct Content-Length for the request, allowing vibe to skip reading the body if it needs to.

I also have this section in my server config:


location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|woff|eof|ttf)$ {
      root /path/to/statics;
   }

which means that nginx serves the static files directly, skipping vibe. This seems like the best setup to me.

Things that should be improved are:

* More security! While this set up isn't actually insecure, I'm sure something could be done to make it better. * using `try_files`, nginx complains that you can't use proxy_pass inside a named location (like `@vibe`), which means you can't use try_files to serve arbitrary static files, hence the massive list of extensions.

So far I'm loving vibe.d, it is fast and flexible and just works (mostly). With nginx serving the static files out the front, the speed of the setup is incredible.

I hope that people find this helpful.

--
James Miller

Reply via email to