Issue
I have a Ubuntu server running Nginx and Docker. My docker container is running on port 4200.
docker run -d -p4200:4200 my-app:latest
I can verify that it is running
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5be8856b9e2 my-app:latest "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 80/tcp, 0.0.0.0:4200->4200/tcp hopeful_diffie
I have setup up my Nginx default config file like so:
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name my-app.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:4200/;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-app.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-app.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name www.my-app.com; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:4200/;
}
listen [::]:443 ssl ; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-app.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-app.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = my-app.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [:
:]:80 default_server;
server_name my-app.com;
return 404; # managed by Certbot
}
server {
if ($host = www.my-app.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name www.my-app.com;
return 404; # managed by Certbot
}
Before I tried adding the proxy_pass (switching the proxy_pass lines to try_files $uri $uri/ =404;) I was getting the default nginx page. I would expect that adding the proxy_pass lines would forward request to the server's port 4200 where the docker container is running. Instead I am getting a 502 Bad Gateway. I am assuming the problem lies in my Ngnix configuration but I am not sure what I am doing wrong? Any help would be great.
Solution
It was a dumb error on my part, but maybe this will help someone in the future. It was in my docker run command.
docker run -d -p 4200:80 my-app:latest
Inside my docker container was listening on 80 but i was sending it to 4200.
Answered By - seanmt13 Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.