Tuesday, 14 March 2017

Heroku + Node (Parse server) + nginx not working

I know that there is a similar question but this one is more specific because I have a nginx server set up but the location parameters are not having any influence:

Here is my nginx.conf.erb:

daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
    use epoll;
    accept_mutex on;
    worker_connections 1024;
}

http {

    gzip on;
    server_tokens off;

    log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
    access_log logs/nginx/access.log l2met;
    error_log logs/nginx/error.log;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    #Must read the body in 5 seconds.
    client_body_timeout 5;

    upstream app_server {
        server unix:/tmp/nginx.socket fail_timeout=0;
    }

    server {
        listen <%= ENV["PORT"] %>;
        server_name _;
        keepalive_timeout 5;

        # A try to override some pictures in parse
        # location /parse/files/0B5jvlihE6yxQed1w9vRSRW0DRldy3fbwqaCjpyF/ {
        #   add_header whereamI first;
        #   return 301 http://www.immobleupromotion.com/wp-content/uploads/2016/07/nice-ouest.jpg;
        # }

        # location /parse/files/{
        #   add_header whereamI second;
        #   return 301 http://www.immobleupromotion.com/wp-content/uploads/2016/07/nice-ouest.jpg;
        # }
        # location / {
        #   add_header whereamI parent;
        #   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #   proxy_set_header Host $http_host;
        #   proxy_redirect off;
        #   proxy_pass http://app_server;
        # }
    }
}

Here is my Procfile:

web: bin/start-nginx ./node_modules/.bin/forever index.js

Here is my index.js (at least the relevant part):

var httpServer = require('http').createServer(app);
httpServer.listen('/tmp/nginx.socket', function () {
    fs.openSync('/tmp/app-initialized', 'w');   
});

Last but not least: here are my buildpacks

=== super-project Buildpack URLs
1. https://github.com/heroku/heroku-buildpack-nodejs.git
2. https://github.com/heroku/heroku-buildpack-nginx.git

And the problem is actually that... this is working: the server returns via nginx all the wished responses BUT it basically shouldn't because that means that the nginx proxy is totally useless and I cannot get why.

Any ideas?



via Laurent Meyer

No comments:

Post a Comment