端口80上的heroku + nginx [英] heroku + nginx on port 80

查看:166
本文介绍了端口80上的heroku + nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在heroku free environmnent上启动一个nginx服务器。我准备好了任何方法和教程,但是我没有得到它。



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



如果我通过Dyno启动nginx,在日志中

pre $ 状态从开始变为崩溃

我的Dyno的Procfile

  web:bin / start-nginx 

我的nginx.config.erb

 守护进程关闭; 
#Heroku dynos至少有4个核心。
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;

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

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

位置/ {
autoindex on;
}
}
}

我也将PORT变量设置为80

  heroku config:get PORT 


其他一些配置:

  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的变量。什么错误?非常感谢任何人。

Btw:我的express服务器在端口1000上运行时没有任何错误(对于测试,我也在端口80上启动它,没有任何错误)

解决方案

我用这个配置解决了我的问题。

  daemon off ; 
#Heroku dynos至少有4个核心。
worker_processes<%= ENV ['NGINX_WORKERS'] || 4%>;

pid nginx.pid;

事件{
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;

包含mime.types;

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

位置/ {
autoindex on;
}
}
}


im trying to start a nginx server on heroku free environmnent. I ready any how-tos and tutorial, but i dont get it running.

First of all, i would like to start nginx as default web-server on Port 80. Afterwards i would like configure nginx as proxy for the underline express server (other heroku instance). For 4 days i trying to start only nginx on my heroku instance. I always getting the exception that not permitted to start on port 80. I forked the nginx-buildback (https://github.com/moohkooh/nginx-buildpack) from (https://github.com/benmurden/nginx-pagespeed-buildpack) to adjust some configuration. If i run nginx via heroku bash on port 2555, nginx is starting, but i get connection refused on web-browser.

If i starting nginx via Dyno i getting error message on logs

  State changed from starting to crashed

the Procfile of my Dyno

  web: bin/start-nginx

My 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; 
         }
     }
}

I also set PORT variable to 80

 heroku config:get PORT
 80

Some other configuration:

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

My .buildpack file

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

I also have the guess, that heroku dont use my variable that i set to 80. Whats wrong? Big thanks for anyone.

Btw: my express server running without any error on port 1000 (for test i start it also on port 80 without any errors)

解决方案

i solved my problem with this configuration.

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; 
        }
    }
}

这篇关于端口80上的heroku + nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆