I configured nginx and after building docker image and run sudo docker-compose up
, it has no error, but the problem is web server with given host doesn't load:
Unable to connect
Firefox can’t establish a connection to the server at localhost:4200.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web.
I have defined nginx.conf
file:
server {
listen 80;
location / {
proxy_pass http://localhost:4200; # Angular service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /api/ {
proxy_pass http://localhost:8000; # Django service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
And also I created Dockerfile for it:
FROM nginx:latest
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
docker-compose
for nginx:
nginx:
build:
context: .
dockerfile: Dockerfile
container_name: auralab-nginx
ports:
- "80:80"
depends_on:
# - angular
- django
I tried both to put my actual server ip in proxy pass but doesn't work, it's 34.159.204.45
.
Any solutions ?
The localhost address points to the container itself. Instead of using:
proxy_pass http://localhost:4200;
use:
proxy_pass http://angular:4200;
Where angular is service name, like nginx from docker-compose file