nginx - 无法让 Heroku 和 Nginx 重定向 http 请求 -> http

标签 nginx heroku heroku-toolbelt

我正在使用 heroku/nodejshttps://github.com/heroku/heroku-buildpack-nginx.git 构建包。

我已经创建了所需的 /app/congig/nginx.conf.rb 文件,我在构建日志中看到了这个文件,`

我在 heroku 日志 输出中看到了这一点:使用命令“bin/start-nginx npm run start”启动进程

所以我知道 nginx 正在运行。但当我向应用程序发出请求时,我也会在响应 header 中看到 Server: Cowboy。所以我不知道为什么我的配置会完全绕过 NGINX 并由 Cowboy 提供服务??

这是我的 nginx.conf.rb:

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 debug;
	error_log stderr info;

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

	#Must read the body in 5 seconds.
	client_body_timeout 5;

	upstream app_server {
		server unix:/tmp/nginx.socket fail_timeout=0;
 	}

	server {
		listen <%= ENV["PORT"] %>;
		server_name _;

		keepalive_timeout 5;

    root   /app/build;

		location / {
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Host $http_host;
      proxy_redirect off;
			if ($http_x_forwarded_proto != 'https') {
        rewrite ^ https://$host$request_uri? permanent;
      }

			proxy_pass app_server;
		}
	}
}

此外..我不知道 error.log 和 access.log 文件在哪里!我什至尝试将它们设置为 /var/log/access|error.log ,但不……当我使用 heroku run -a app- 查看时,它们不在服务器上命名bash!

不知道如何让它工作......请帮忙。

最佳答案

显然 nginx“buildpack”要求您触摸 /tmp 中的文件在它会打扰启动 nginx 之前...

所以添加fs.closeSync(fs.openSync('/tmp/app-initialized', 'w'))我的 Node 应用程序允许 nginx 启动并处理重定向。

关于nginx - 无法让 Heroku 和 Nginx 重定向 http 请求 -> http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48532279/

相关文章:

heroku 客户端内部错误 - 控制台超时

ruby-on-rails - 有子文件夹显示index.html - Rails/nginx

c++ - 使用 Nginx 在 C++ 中编写 REST 服务

Nginx 作为 websockets 和 post 请求的转发代理

google-app-engine - 通过代理使用 Google App Engine 的位置服务

heroku - 在不同机器上设置heroku环境

javascript - React 更改组件顺序不会触发重新渲染

Heroku 和 Liferay 安装

git - 如何在多次推送后重新设置 git 历史记录,然后推送更新的历史记录?

node.js - 将 Node.js 应用程序部署到 Heroku 的问题