From 2e5401d174b64be729f08b7e3af98f4591fa7ec3 Mon Sep 17 00:00:00 2001 From: Abin Date: Thu, 3 Aug 2023 12:01:19 +0530 Subject: [PATCH] nginx successfull configured --- client/Dockerfile | 2 +- client/src/config.ts | 2 +- conf.d/tutortrek.online.conf | 16 ++++++++-------- docker-compose.yml | 25 +++++++++---------------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/client/Dockerfile b/client/Dockerfile index 1386943..958cbdf 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -32,7 +32,7 @@ RUN rm -rf /usr/share/nginx/html/* # Copy the built React app from the build stage COPY --from=build /usr/src/reactapp/build /usr/share/nginx/html -EXPOSE 3000 +EXPOSE 80 # Start nginx server CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/client/src/config.ts b/client/src/config.ts index b5d9b4c..3f31edb 100644 --- a/client/src/config.ts +++ b/client/src/config.ts @@ -2,6 +2,6 @@ const CONFIG_KEYS = { GOOGLE_AUTH_CLIENT_ID: process.env.REACT_APP_CLIENT_ID as string, STRIPE_PUBLISHABLE_KEY: process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY as string, REDIRECT_URI: process.env.REACT_APP_REDIRECT_URI as string, - API_BASE_URL: "http://tutortrek.online", + API_BASE_URL: process.env.API_BASE_URL as string, }; export default CONFIG_KEYS; diff --git a/conf.d/tutortrek.online.conf b/conf.d/tutortrek.online.conf index 207f198..9604edd 100644 --- a/conf.d/tutortrek.online.conf +++ b/conf.d/tutortrek.online.conf @@ -4,24 +4,24 @@ upstream backend { server { listen 80; - server_name tutortrek.online; + server_name localhost; # Use a dummy value for testing location / { - root /usr/share/nginx/html; - index index.html; - - try_files $uri $uri/ /index.html; + root /usr/share/nginx/html; + index index.html; + # Other config you desire (TLS, logging, etc)... + try_files $uri /index.html; } location /api { - proxy_pass http://backend; + proxy_pass http://backend; # Load balancing for server proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - location /static { - alias /usr/share/nginx/html; + location /static { + alias /usr/share/nginx/html/static; # Add the /static path } } diff --git a/docker-compose.yml b/docker-compose.yml index 3185e9d..a91b9bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,17 +6,14 @@ services: dockerfile: Dockerfile image: abin11/tutortrek_client:latest container_name: tutortrek_client - ports: - - "3000:3000" - #volumes: - #- static_files:/usr/share/nginx/html/static # Mount the volume to serve static files - #- ./client/build:/usr/src/reactapp/build # Mount the React build directory to the volume + volumes: + - ./client/build:/usr/src/reactapp/build env_file: - ./client/.env depends_on: - server networks: - - connection_network + - tutortrek_connection_network deploy: resources: limits: @@ -34,7 +31,7 @@ services: depends_on: - redis networks: - - connection_network + - tutortrek_connection_network healthcheck: test: ["CMD", "curl", "-f", "http://localhost:4000/health"] interval: 30s @@ -52,27 +49,23 @@ services: - ./.db:/data restart: always networks: - - connection_network + - tutortrek_connection_network nginx: image: nginx:alpine volumes: - ./conf.d:/etc/nginx/conf.d - #- static_files:/usr/share/nginx/html/static # Mount the volume to serve static files - #- /path/to/your/ssl/certs:/etc/nginx/ssl # Add this line - - ./client/build:/usr/share/nginx/html # Mount the complete React build directory + - ./client/build:/usr/share/nginx/html depends_on: - server - client ports: - - "80:80" + - "4000:80" # Expose Nginx's port 80 to host port 4000 - "443:443" networks: - - connection_network + - tutortrek_connection_network networks: - connection_network: + tutortrek_connection_network: driver: bridge -volumes: - static_files: # Define the static_files volume