RejectedSoftware Forums

Sign up

Vibe + nginx

Hello!

I'm trying to run vibe application behind nginx http server.

My stuff:

////app.d
import vibe.d;

void index(HttpServerRequest req, HttpServerResponse res) {

res.render!("index.dt");

}

static this() {

auto router = new UrlRouter;
router.get("/", &index);

auto settings = new HttpServerSettings;

settings.bindAddresses = [
"127.0.0.1"
];

settings.port = 6174;

listenHttp(settings, router);

}
////

/////etc/nginx/sites-enabled/mydomain.com
server {

 listen	80;

 server_name .mydomain.com;
 access_log /var/www/mydomain.com/log/access.log;
 error_log /var/www/mydomain.com/log/error.log;

 location / {
auth_basic "Success Denied";
auth_basic_user_file /var/www/mydomain.com/.htpasswd;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_set_header X-NginX-Proxy true;
     proxy_pass http://127.0.0.1:6174;
     proxy_redirect off;
 }

}
////

After that, then i type http://mydomain.com in my browser,
response from nginx is 504 Gateway Timout.
But then i comment out the bindAddresses assigning and type
http://xx.xx.xx.xx:6174 (where xx.xx.xx.xx is an IP of the actual
server machine), all is ok.

Similar configs successfully work with node.js applications.

Does anyone know where i'm wrong?

Thanx.

Stanislav

Re: Vibe + nginx

James Miller has posted a working configuration some time ago on the D
newsgroup:

http://forum.dlang.org/thread/mgoveqnyimerdazvjqgb@forum.dlang.org

I think the main issue is that nginx 1.0.x does not support HTTP/1.1 for
its reverse proxy but vibe.d often needs it for chunked transfers. The
thing with "proxysetheader Content-Length $bodybytessent;"
sounds like a bug though and I will look into it.

Regards

Re: Vibe + nginx

On Wednesday, 22 August 2012 at 19:26:53 UTC, Sönke Ludwig wrote:

James Miller has posted a working configuration some time ago
on the D newsgroup:

http://forum.dlang.org/thread/mgoveqnyimerdazvjqgb@forum.dlang.org

I think the main issue is that nginx 1.0.x does not support
HTTP/1.1 for its reverse proxy but vibe.d often needs it for
chunked transfers. The thing with "proxysetheader
Content-Length $bodybytessent;" sounds like a bug though
and I will look into it.

Regards

Big thanx to you and James Miller! You saved me.

As a result - working config for nginx 1.1.14:

server {

 listen	80;

 server_name .domain.name;
 access_log /var/www/domain.name/log/access.log;
 error_log /var/www/domain.name/log/error.log;

 location / {
auth_basic "Success Denied";
auth_basic_user_file /var/www/domain.name/.htpasswd;
root /var/www/domain.name/static;
try_files $uri @vibe;
 }

 location @vibe {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $host;
     proxy_set_header X-NginX-Proxy true;

     proxy_pass http://localhost:6174;
     proxy_redirect off;
proxy_pass_request_body on;
proxy_set_body $request_body;
proxy_http_version 1.1;
 }

}