nginx - 80 端口上的 heroku + nginx

标签 nginx heroku

我正在尝试在 heroku 免费环境中启动 nginx 服务器。我准备好了任何操作方法和教程,但我无法运行它。

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

如果我通过 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 的变量。出了什么问题?非常感谢任何人。

顺便说一句:我的 Express 服务器在端口 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; 
        }
    }
}

关于nginx - 80 端口上的 heroku + nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44586218/

相关文章:

python - Arch Nginx Uwsgi 未加载应用程序

NGINX:主位置 block 覆盖子目录位置?

ruby-on-rails - 在 puma 和 nginx 上运行的 Rails 应用程序每隔几个小时就会因 Bad Gateway 而死掉

ruby-on-rails - Nginx、 unicorn 和 Heroku

ruby-on-rails - Heroku - 在文件系统边界处停止(未设置 GIT_DISCOVERY_ACROSS_FILESYSTEM)

nginx - 无法在 Mac OS X 上卸载 nginx

Nginx缓存目录为空

postgresql - 如何为 postgresql 连接到我的 heroku 共享数据库?

javascript - Rails - jQuery 不适用于 Heroku 的生产环境

javascript - Heroku + Node : Cannot find module error