Nginx未加载网页

ltskdhd1  于 7个月前  发布在  Nginx
关注(0)|答案(1)|浏览(93)

我配置了nginx,在构建Docker镜像并运行sudo docker-compose up后,它没有错误,但问题是加载了给定主机的Web服务器:

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.

字符串
我已经定义了nginx.conf文件:

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;
    }
}


还有Dockerfile:

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


我试图把我的实际服务器IP在代理通行证,但不工作,其34.159.204.45任何解决方案?

gpfsuwkq

gpfsuwkq1#

localhost地址指向容器本身。而不是使用:
第一个月
用途:
proxy_pass http://angular:4200;
其中angular是服务名称,类似于docker-compose文件中的nginx

相关问题