【发布时间】:2017-11-19 01:15:20
【问题描述】:
我正在尝试在 heroku 免费环境中启动 nginx 服务器。我准备了任何方法和教程,但我没有让它运行。
首先,我想在端口 80 上启动 nginx 作为默认网络服务器。之后我想将 nginx 配置为下划线快速服务器(其他 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 正在启动,但我在网络浏览器上收到连接被拒绝。
如果我通过 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 上启动它而没有任何错误)
【问题讨论】:
-
你试过不强制端口到80吗?我不更改端口,因为 Heroku 设置了它。 “每个 Web 进程只是绑定到一个端口,并监听来自该端口的请求。要绑定的端口由 Heroku 分配为 PORT 环境变量。” -- devcenter.heroku.com/articles/runtime-principles
-
是的,我正在尝试。 Heroku 使用“随机”端口启动 nginx,但我也没有通过浏览器响应。正如我所读到的,如果我将端口设置为 80,它们应该从端口 80 或环境设置的端口开始。