make nginx more resilient so you can start the api without the webapp (#37)

This commit is contained in:
Nathan Sarrazin 2023-03-23 21:48:16 +01:00 committed by GitHub
parent f117895571
commit aa257db1e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -10,6 +10,7 @@ services:
- /etc/localtime:/etc/localtime:ro
depends_on:
- mongodb
- nginx
env_file:
- .env
command: uvicorn main:app --reload --host 0.0.0.0 --port 9124 --root-path /api/
@ -32,6 +33,9 @@ services:
- ./web:/usr/src/app/
- /usr/src/app/node_modules
command: npm run dev -- --host 0.0.0.0 --port 9123
depends_on:
- api
- nginx
nginx:
build:
context: ./nginx

View File

@ -1,9 +1,15 @@
server {
listen 80; # Adjust the port number if needed
server_name localhost;
resolver 127.0.0.11;
set $api api:9124;
set $web web:9123;
# Proxy requests for the root URL to Service A
location / {
proxy_pass http://web:9123;
proxy_pass http://$web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -16,12 +22,11 @@ server {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# Proxy requests for /api to Service B
location /api/ {
proxy_pass http://api:9124;
proxy_pass http://$api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;