一, 打包react項目
1,在工作空間目錄下create-react-app test-arrange 創建項目test-arrange
2,在新建的項目中寫好請求與頁面
3,打包, 在項目目錄下 npm run build
打包完成之后, 在項目目錄下出現build文件夾。
二, 下載安裝Windows版Nginx
1,Nginx下載地址http://nginx.org/en/download.html
下載的是穩定版1.16.1
2,解壓
3,將步驟一中打包后生成的build文件夾內文件復制到nginx -> html目錄下[不一定是html目錄,可以在nginx.conf中修改;location/里面的root]
4,修改nginx -> conf目錄下配置文件nginx.conf
PS: 如果步驟一的2和步驟二的4中不加api訪問后台接口的時候會報404
5,啟動Nginx, 在nginx目錄下 start nginx
6,訪問, http://localhost:8081,因為是Windows版的nginx所以是localhost,如果nginx是在Linux服務器上,localhost改為相應ip地址
點擊search,可以從后台取到數據
7,停止nginx, 在nginx目錄下nginx -s quit