Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未在浏览器中打开nginx和gunicorn的docker_Docker_Nginx - Fatal编程技术网

未在浏览器中打开nginx和gunicorn的docker

未在浏览器中打开nginx和gunicorn的docker,docker,nginx,Docker,Nginx,我不熟悉Docker并使用gunicorn和nginx设置Docker运行Django应用程序 我的配置文件是 docker compose.yml version: '3' services: nginx: image: nginx:latest container_name: "myapp-nginx" ports: - "10080:80" - "10443:43" volumes: - .:/app -

我不熟悉
Docker
并使用
gunicorn
nginx
设置
Docker
运行
Django
应用程序

我的配置文件是

docker compose.yml

version: '3'

services:
  nginx:
    image: nginx:latest
    container_name: "myapp-nginx"
    ports:
      - "10080:80"
      - "10443:43"
    volumes:
      - .:/app
      - ./config/nginx:/etc/nginx/conf.d
      - ./static_cdn:/static
    depends_on:
      - web
  web:
    build: .
    container_name: "myapp-dev"
    command: ./start.sh
    volumes:
      - .:/app
      - ./static_cdn:/static
    ports:
      - "9010"
    depends_on:
      - db
    expose:
      - "9010"
  db:
    image: postgres
    container_name: "myapp-db"
config/nginx/nginx.conf

upstream web {
    ip_hash;
    server web:9010;
}

server {
    location /static {
        autoindex on;
        alias /static/;
    }

    location / {
        proxy_pass http://web;
    }
    listen 9010;
    server_name localhost;
}
start.sh

#!/usr/bin/env bash

# Start Gunicorn processes
echo --: Starting application build
echo --: Creating migration
python3 manage.py makemigrations
echo ------: makemigrations complete
echo --: Running migration
python3 manage.py migrate
echo ------: migrate complete
echo --: Running collectstatic
python3 manage.py collectstatic <<<yes
echo ------: collectstatic complete
echo --: Starting Gunicorn.
gunicorn koober.wsgi:application \
    --bind 0.0.0.0:9010 \
    --workers 3
它成功运行,输出为

此处,gunicorn在
0.0.0.0:9010成功启动。但无法使用浏览器访问应用程序。

我尝试在浏览器中跟踪地址

  • 127.0.0.1:9010
  • 127.0.0.1:10080
  • 127.0.0.1
  • 本地主机:9010
  • 本地主机:10080
  • 本地主机
  • 0.0.0.0:9010
  • 0.0.0.0:10080
  • 0.0.0.0
  • 但它们都不起作用

    编辑2:docker ps-a的输出

    试试这个

    upstream web {
      ip_hash;
      server web:9010;
    }
    server {
    
     listen       10080;
    
     location / {
        proxy_pass http://web;
     }     
    }
    
    Nginx应该在10080端口上侦听,因为在您的compose文件中,您已经公开了端口80到10080端口

    然后尝试

    下面是我写的博客,解释Docker+Nginx+Web应用程序是如何协同工作的

    源代码

    我试过了,但没有成功。我使用返回的
    192.168.31.13
    ipconfig getifaddr en0
    找到了ip地址,我也尝试了这个ip地址,但没有成功。我已经在使用nginx并作为核心服务运行的mac机上设置了
    valet
    。它是否影响了这一点?还有一件事-在您的docker compose web文件中,您可以尝试端口:-“9010:9010”并删除暴露标记。是的,我将9010:9010添加到
    web
    ,并在
    127.0.0.1:9010
    下工作。但无法理解港口的流量。我们增加了
    listen10080到nginx conf,它正在
    9010
    上工作。你能解释一下它的工作原理吗?它应该在10080端口上工作,你能交叉检查一下你的Nginx配置文件吗。最后,您应该能够点击127.0.0.1:10080 url,它会自动将您重新定向到web服务器。
    upstream web {
      ip_hash;
      server web:9010;
    }
    server {
    
     listen       10080;
    
     location / {
        proxy_pass http://web;
     }     
    }