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
services: flask_app: build: context: ./flask container_name: flask ports: - "5000:5000" networks: - frontend - backend volumes: - ./flask:/var/www/flask tty: true environment: TZ: Asia/Tokyo command: flask run --host 0.0.0.0 --port 5000 react_app: build: context: ./front container_name: react volumes: - ./front/:/usr/src/app environment: CHOKIDAR_USEPOLLING: "true" command: sh -c "cd react-app && yarn install && yarn dev" ports: - "3000:3000" networks: - frontend tty: true stdin_open: true nginx: build: context: ./nginx container_name: nginx ports: - "80:80" volumes: - ./front/react-app/dist:/var/www - ./nginx/:/etc/nginx/conf.d/ depends_on: - react_app networks: - frontend networks: frontend: driver: bridge backend: driver: bridge
nginx.conf
server { listen 80; location / { root /var/www; index index.html index.htm; try_files $uri /index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location /api { proxy_pass http://flask:5000; } }
まだ回答がついていません
会員登録して回答してみよう