我关注了这两个帖子,但没有任何运气
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下创建此应用程序
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;
}尽管如此,我还是没能让反向代理正常工作。
有谁能帮我一下吗?
感谢您的帮助和建议。
发布于 2019-04-24 03:57:11
您是否注意到您正在使用nginx配置中的端口8081,而不是您的应用程序的端口(8000)?
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}https://stackoverflow.com/questions/55069430
复制相似问题