Reputation: 59
I have the following stack:
I want to deploy them into an ELB application.
When I do that and try to access the instance I get 502 Bad Gateway nginx/1.18.0 instead of the home page.
The backend is up and running on port 8081 (made external request via postman and works properly)
The problem is with the static content.
Here's my code for proxy.config file (ebextensions for nginx)
/etc/nginx/conf.d/proxy.conf:
owner: root
group: root
mode: "000644"
content: |
upstream nodejs {
server 127.0.0.1:8081;
keepalive 32;
}
server {
root /var/app/current/react_build;
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 /api/ {
proxy_pass http://nodejs;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10M;
}
location /static/ {
}
location / {
try_files '' /index.html =404;
}
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
/opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
owner: root
group: root
mode: "000755"
content: |
#!/bin/bash -xe
rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
service nginx stop
service nginx start
container_commands:
removeconfig:
command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"```
Upvotes: 3
Views: 728
Reputation: 239005
The nginx
config file (/etc/nginx/conf.d/proxy.conf
) you are trying to set is for Amazon Linux 1 (AL1).
For AL2, the nginx
config files should be provided (aws docs) using:
.platform/nginx/conf.d/
or if you want to overwrite main nginx
config file, use
.platform/nginx/nginx.conf
Upvotes: 2