react,flask,niginx,msqlのコンテナを作成したプリケーションを作っています
開発環境では以下いずれともブラウザからアクセス可能なのですが
localhost:3000/
http://localhost/
本番環境の場合、port:3000は受け付けないので以下でブラウザアクセスします。
http://ipaddress/
フロント(react)については当たり前ですがブラウザからちゃんと表示されているのですが
以下エラーとなりflaskとの接続ができません。
localhost:5000/api/user_get:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
コンテナが上がっているサーバー上にてcurlコマンドでAPIを呼び出すと以下のどちらも形式も応答します
curl localhost:5000/api/user_get
curl ipaccress:5000/api/user_get
おそらく初歩的な部分の知識不足と思いますが、本番環境でflaskとの接続をするにはどのあたりを見るべきでしょうか
念のため以下のymlとnginxのコンフィグを張ります
dockercompose.yml
1 2services: 3 flask_app: 4 build: 5 context: ./flask 6 container_name: flask 7 ports: 8 - "5000:5000" 9 networks: 10 - frontend 11 - backend 12 volumes: 13 - ./flask:/var/www/flask 14 tty: true 15 environment: 16 TZ: Asia/Tokyo 17 command: flask run --host 0.0.0.0 --port 5000 18 19 react_app: 20 build: 21 context: ./front 22 container_name: react 23 volumes: 24 - ./front/:/usr/src/app 25 environment: 26 CHOKIDAR_USEPOLLING: "true" 27 command: sh -c "cd react-app && yarn install && yarn dev" 28 ports: 29 - "3000:3000" 30 networks: 31 - frontend 32 tty: true 33 stdin_open: true 34 35 nginx: 36 build: 37 context: ./nginx 38 container_name: nginx 39 ports: 40 - "80:80" 41 volumes: 42 - ./front/react-app/dist:/var/www 43 - ./nginx/:/etc/nginx/conf.d/ 44 depends_on: 45 - react_app 46 networks: 47 - frontend 48networks: 49 frontend: 50 driver: bridge 51 backend: 52 driver: bridge 53
nginx.conf
1server { 2 listen 80; 3 4 location / { 5 root /var/www; 6 index index.html index.htm; 7 try_files $uri /index.html; 8 } 9 10 error_page 500 502 503 504 /50x.html; 11 location = /50x.html { 12 root /usr/share/nginx/html; 13 } 14 15 location /api { 16 proxy_pass http://flask:5000; 17 } 18} 19

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。