我跟着这两个帖子,但没有运气
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}!`));
以上将确保如果网址是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
下创建它
files:/etc/nginx/conf.d/:owner:root group:root content:|上游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 / {
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;
}