我正在尝试在 heroku 免费环境中启动 nginx 服务器。我准备了任何操作方法和教程,但我无法运行它。
首先,我想在端口 80 上启动 nginx 作为默认 Web 服务器。然后我想将 nginx 配置为 underline express 服务器(其他 heroku 实例)的代理。
4天来我试图在我的heroku实例上只启动nginx。我总是收到不允许在端口 80 上启动的异常。
我分叉了 nginx-buildback (https://github.com/moohkooh/nginx-buildpack https://github.com/moohkooh/nginx-buildpack) from (https://github.com/benmurden/nginx-pagespeed-buildpack 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 上启动它,没有任何错误)