端口80上的heroku nginx

即时尝试在heroku free environmnent上启动nginx服务器.我准备了任何方法和教程,但我没有让它运行.

首先,我想在端口80上启动nginx作为默认的Web服务器.之后我想配置nginx作为下划线express服务器(其他heroku实例)的代理.
4天我试图在我的heroku实例上只启动nginx.我总是得到不允许在端口80上启动的异常.
我从(https://github.com/benmurden/nginx-pagespeed-buildpack)分叉了nginx-buildback(https://github.com/moohkooh/nginx-buildpack)来调整一些配置.如果我通过端口2555上的heroku bash运行nginx,nginx正在启动,但我在Web浏览器上拒绝连接.

如果我通过Dyno启动nginx我在日志上收到错误消息

  State changed from starting to crashed

我的Dyno的Procfile

  web: bin/start-nginx

我的nginx.config.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;
     gzip_comp_level 2;
     gzip_min_length 512; 

     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;

     server {
         listen <%= ENV['PORT'] %>;
         server_name _; 
         keepalive_timeout 5; 
         root /app/www;
         index index.html;

         location / {
             autoindex on; 
         }
     }
}

我还将PORT变量设置为80

 heroku config:get PORT
 80

其他一些配置:

 heroku config:get NGINX_WORKERS
 8
 heroku buildpacks
 https://github.com/heroku/heroku-buildpack-multi.git
 heroku stack
 cedar-14

我的.buildpack文件

https://github.com/moohkooh/nginx-buildpack
https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/ruby.tgz

我也有猜测,heroku不使用我设置为80的变量.怎么回事?非常感谢任何人.

顺便说一句:我的快递服务器在端口1000上没有任何错误运行(对于测试我也在端口80上启动它而没有任何错误)

最佳答案 我用这个配置解决了我的问题.

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

pid nginx.pid;

events { 
    worker_connections 1024; 
}

http {
    gzip on;
    gzip_comp_level 2;
    gzip_min_length 512; 
    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;

    server {
        listen <%= ENV['PORT'] %>;
        server_name localhost;
        port_in_redirect off;
        keepalive_timeout 5; 
        root /app/www; 
        index index.html;

        location / {
            autoindex on; 
        }
    }
}
点赞