From 382f2db83e493af48d4ebe401c8d86b76a819366 Mon Sep 17 00:00:00 2001 From: PeterStayPool Date: Sat, 4 Jan 2025 23:27:26 -0600 Subject: [PATCH 1/2] add nginx readme --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 58beeacc..122e8273 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,45 @@ +## Example webservice project with Flask and React + + +# Deploying the web service project to production + +## 1. Installing the nginx locally + +> brew install nginx + +For Mac, nginx will be installed in the following path: +>/opt/homebrew/opt/nginx/bin/ + +Default nginx docroot (folder that nginx load website) is +>/opt/homebrew/var/www + +For configuration of nginx, you need to look at this location. +> /opt/homebrew/etc/nginx/nginx.conf +By default, nginx listen to 8080. + +To start the nginx in daemon mode, run this +>brew services start nginx + +nginx will load files in `/opt/homebrew/etc/nginx/servers/`. + +If you want to run nginx in forground mode, run this +>/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\; +``` +Docroot is: /opt/homebrew/var/www + +The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that +nginx can run without sudo. + +nginx will load all files in /opt/homebrew/etc/nginx/servers/. + +To start nginx now and restart at login: + brew services start nginx +Or, if you don't want/need a background service you can just run: + /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\; +``` + + + # Getting Started with Create React App This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). From e45094654a86f4ccc4de14db28226d33671e988a Mon Sep 17 00:00:00 2001 From: PeterStayPool Date: Tue, 7 Jan 2025 00:44:41 -0600 Subject: [PATCH 2/2] added more instruction for production deployment --- .gitignore | 3 ++- README.md | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index efb7ef56..cfc4c9e6 100644 --- a/.gitignore +++ b/.gitignore @@ -171,4 +171,5 @@ cython_debug/ .pypirc venv -__pycache__ \ No newline at end of file +__pycache__ +.DS_Store diff --git a/README.md b/README.md index 122e8273..8d31d28e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ # Deploying the web service project to production +## STEP1: install the nginx to load your project directly from the build folder. + ## 1. Installing the nginx locally > brew install nginx @@ -19,26 +21,50 @@ By default, nginx listen to 8080. To start the nginx in daemon mode, run this >brew services start nginx - nginx will load files in `/opt/homebrew/etc/nginx/servers/`. If you want to run nginx in forground mode, run this >/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\; + +### change the nginx.conf (/opt/homebrew/etc/nginx/nginx.conf) for local development. +Since we are not deplying to the actual server with dedicated nginx install(we will explort that option later.), we just want to check if nginx can load our production ready built project directly. + +To do so, we need to instruct nginx to load the index.html from the `\build` folder. Make the following changes in the original `nginx.conf`. + ``` -Docroot is: /opt/homebrew/var/www +... some other configuration you don't need to touch .... +http { +... some other configuration you don't need to touch .... + server { + listen 8080; --> we are listening to 8080 for development. + root /Users/peterhan/workspace/example_webservice/build; + index index.html; + +... some other configuration you don't need to touch .... + + location / { + try_files $uri $uri/ =404; + #root html; --> comment that out for now + #index index.html index.htm; --> comment that out for now. + } +... some other configuration you don't need to touch .... -The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that -nginx can run without sudo. +``` -nginx will load all files in /opt/homebrew/etc/nginx/servers/. +To restart the nginx after changing the nginx.config, run this command (only for mac) +``` +$ brew services restart nginx +--> the following will be printed out. +Stopping `nginx`... (might take a while) +==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx) +==> Successfully started `nginx` (label: homebrew.mxcl.nginx) -To start nginx now and restart at login: - brew services start nginx -Or, if you don't want/need a background service you can just run: - /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\; +$ nginx -s reload ``` +If anything in `nginx.conf` is wrong, it will fail. +Now, open the browser and type `localhost:8080`. # Getting Started with Create React App