amazon-web-services - aws elastic beanstalk nginx 反向代理设置
问题描述
我关注了这两个帖子,但没有任何运气
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html
https://davidojeda.mx/blog/2018/01/11/extend-nginx-config-on-aws-elasticbeanstalk
我刚开始elastic beanstalk
在手边玩。
有了基础,我启动了服务器,port:8000
我想做一个反向代理,所以它会监听端口 80。
我一开始并没有这样做elb
,因为我想在进入之前更多地了解基础知识elb
这是我index.js
的运行应用程序
const express = require('express');
const app = express();
const port = 8000;
app.get('/', async (req, res) => {
return res.json({ status: true });
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
如果 url 是这样,以上内容肯定会起作用,http://eb_self_generated_url:8000
所以我想让它使用https://eb_self_generated_url
我正在阅读一些帖子,但它们都不起作用。
在我的根里,我创造了.ebextensions/nginx/conf.d/s_proxy.conf
,在里面我有
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
access_log /var/log/nginx/access.log main;
location / {
# this is actually what need to be changed
# I tried changing from http://nodejs to http://localhost:8000 at server which then will make the reverse proxy work
proxy_pass http://localhost:8000;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml appl$
}
我试图压缩上面的东西,update / deploy
但没有任何变化
我也尝试在我的应用程序下创建它.ebextensions/proxy.conf
文件:/etc/nginx/conf.d/:所有者:root 组:root 内容:| 上游 nodejs { 服务器 127.0.0.1:8081; 保活256;}
server {
listen 8080;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
access_log /var/log/nginx/access.log main;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml appl$
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/01_static.conf;
include conf.d/elasticbeanstalk/healthd.conf;
}
我仍然没有让反向代理工作的运气。
谁能帮我一把?
感谢您的任何帮助和建议。
解决方案
您是否注意到您在 nginx 配置中使用端口 8081 而不是应用程序的端口 (8000)?
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
推荐阅读
- visual-studio-code - 在远程主机上开发 vscode 扩展
- java - 应用程序在后台时显示 DialogFragment
- c# - 调用客户端 API 后如何再次启动 USSD 会话
- excel - 在自定义任务窗格上捕获控件实例
- fluentd - 我可以有选择地禁用单个 fluentd 插件而不将它们从配置文件中删除吗?
- java - 如何摆脱Android应用栏中的后退按钮
- markdown - pandoc-cite-proc 选项是否有扩展名?
- jupyter-notebook - Jupyter 笔记本在 [*] 停止
- mongodb - 如何使用 mongoose 从 mongodb 中删除重复的名称?
- python - 如何在 vtk 中初始化三角形网格