【发布时间】:2021-08-01 05:42:42
【问题描述】:
我一直在尝试将我的第一个完整 MERN 堆栈部署到实际服务器而不是 Heroku 和 Netlify,
我买了一个 ubuntu 操作系统的服务器,
- 我设置了服务器,
2.安装了nodejs、pm2、Nginx
-
我使用 ssh 复制了 react build 文件夹中的所有文件:
asset-manifest.json favicon.ico index.html logo192.png logo512.png manifest.json robots.txt static``` -
我将 Nginx 设置为将该文件夹作为我在端口 80 中的 IP 的默认请求
server { listen 80; listen [::]:80; root /var/www/qdx/html; index index.html index.htm index.nginx-debian.html; server_name your_domain www.your_domain; location / { try_files $uri $uri/ =404; } }```
到目前为止一切顺利,我可以使用 URL 访问我的网站:http://185.97.117.14/
现在我想在同一台服务器上设置后端,以便它们可以相互连接:
5.我将所有的快速代码复制到服务器的根目录中
```
ubuntu@first:~/server$ ls
config node_modules package.json package-lock.json README.md src
```
然后我使用 pm2 start 设置 pm2
ubuntu@first:~/server$ pm2 show 0
Describing process with id 0 - name qdx-server
???????????????????????????????????????????????????????????????????
? status ? online ?
? name ? qdx-server ?
? namespace ? default ?
? version ? 1.0.0 ?
? restarts ? 0 ?
? uptime ? 7h ?
? script path ? /home/ubuntu/server/src/index.js ?
? script args ? N/A ?
? error log path ? /home/ubuntu/.pm2/logs/qdx-server-error.log ?
? out log path ? /home/ubuntu/.pm2/logs/qdx-server-out.log ?
? pid path ? /home/ubuntu/.pm2/pids/qdx-server-0.pid ?
? interpreter ? node ?
? interpreter args ? N/A ?
? script id ? 0 ?
? exec cwd ? /home/ubuntu/server/src ?
? exec mode ? fork_mode ?
? node.js version ? 16.1.0 ?
? node env ? N/A ?
? watch & reload ? ? ?
? unstable restarts ? 0 ?
? created at ? 2021-05-10T11:55:04.319Z ?
???????????????????????????????????????????????????????????????????
Actions available
??????????????????????????
? km:heapdump ?
? km:cpu:profiling:start ?
? km:cpu:profiling:stop ?
? km:heap:sampling:start ?
? km:heap:sampling:stop ?
??????????????????????????
Trigger via: pm2 trigger qdx-server <action_name>
Code metrics value
??????????????????????????????????????
? Heap Size ? 29.31 MiB ?
? Heap Usage ? 95.33 % ?
? Used Heap Size ? 27.94 MiB ?
? Active requests ? 0 ?
? Active handles ? 4 ?
? Event Loop Latency ? 0.31 ms ?
? Event Loop Latency p95 ? 1.07 ms ?
??????????????????????????????????????
Divergent env variables from local env
?????????????????????????????????????????
? XDG_SESSION_ID ? 18 ?
? SSH_CLIENT ? 5.123.134.1 44336 22 ?
? OLDPWD ? /home/ubuntu/server ?
? SSH_TTY ? /dev/pts/0 ?
? PWD ? /home/ubuntu/server/ ?
? SSH_CONNECTION ? 5.123.134.1 44336 18 ?
?????????????????????????????????????????
6.虽然 express 应用程序应该在端口 5000 中运行 而且我使用了防火墙并提供了对 API 的访问权限,但我似乎无法打开 express 应用程序并使其连接,
ubuntu@first:/etc/nginx/sites-enabled$ sudo ufd sudo:无法先解析主机 sudo:ufd:找不到命令 ubuntu@first:/etc/nginx/sites-enabled$ sudo fwd sudo:无法先解析主机 sudo: fwd: 找不到命令 ubuntu@first:/etc/nginx/sites-enabled$ sudo ufw status sudo:无法先解析主机 状态:活跃
To Action From
-- ------ ----
22 ALLOW Anywhere
80 ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
5000 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
5000 (v6) ALLOW Anywhere (v6)
我一直在研究这个并尝试学习所有东西一个星期,只是为了学习部署, 任何帮助将不胜感激
【问题讨论】:
-
您是否添加了从 nginx 到后端的路由?在此处查看我的示例 nginx 配置 - github.com/taleodor/mafia-vue/blob/master/nginx/… 在此处查看我关于在 SO 中部署所有这些的推荐方式的更详细答案 - stackoverflow.com/questions/63716880/… 也可以随时加入 DevOps 社区 Discord 以获得更多帮助:discord.gg/UTxjBf9juQ
标签: ubuntu nginx deployment server devops