-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centos7 nginx 配置详情 #60
Comments
在 ssh root@33.xx.xx.xx
password: xxxxx 回车后就可以远程连接上服务器了,可以尽情的玩耍了 |
进入之后,我们查看 ps -ef | grep nginx
# 输出如下
root 1754 1 0 11月24 ? 00:00:00 nginx: master process /usr/sbin/nginx # nginx安装目录文件夹
nginx 1755 1754 0 11月24 ? 00:00:00 nginx: worker process
nginx 1756 1754 0 11月24 ? 00:00:00 nginx: worker process
root 3155 2963 0 09:09 pts/1 00:00:00 grep --color=auto nginx 查看配置文件
|
安装 # 安装wget
# 更新源
yum update
# 安装 wget
yum install wget
# 使用 wget 安装 nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
# 将 nvm 添加到配置
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# 查看 nvm
nvm --version
# 使用 nvm 查看所有 node 版本信息
ls-remote
# 使用 nvm 安装 node
nvm install v12.18.4
# 安装完成之后,安装 pm2
# pm2 是管理 node 服务的一个终端命令行,使用请详见 `pm2 -h`
npm install pm2 -g
|
使用 # 启动项目
# 在项目根目录,使用 pm2 启动,或者配置 pm2 配置文件启动,我这里使用前者
>pm2 start app.js
[PM2] Applying action restartProcessId on app [app](ids: [ 0 ])
[PM2] [app](0) ✓
[PM2] Process successfully started
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ app │ fork │ 0 │ online │ 0% │ 9.6mb
# 查看 后台进程
>pm2 list
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ app │ fork │ 0 │ online │ 0% │ 46.9mb
# 查看 pm2 后台日志
>pm2 logs
AILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/root/.pm2/pm2.log last 15 lines:
PM2 | 2020-11-24T23:24:13: PM2 log: RPC socket file : /root/.pm2/rpc.sock
PM2 | 2020-11-24T23:24:13: PM2 log: BUS socket file : /root/.pm2/pub.sock
PM2 | 2020-11-24T23:24:13: PM2 log: Application log path : /root/.pm2/logs
PM2 | 2020-11-24T23:24:13: PM2 log: Worker Interval : 30000
PM2 | 2020-11-24T23:24:13: PM2 log: Process dump file : /root/.pm2/dump.pm2
PM2 | 2020-11-24T23:24:13: PM2 log: Concurrent actions : 2
PM2 | 2020-11-24T23:24:13: PM2 log: SIGTERM timeout : 1600
PM2 | 2020-11-24T23:24:13: PM2 log: ===============================================================================
PM2 | 2020-11-24T23:26:22: PM2 log: App [app:0] starting in -fork mode-
PM2 | 2020-11-24T23:26:22: PM2 log: App [app:0] online
PM2 | 2020-11-25T09:27:28: PM2 log: Stopping app:app id:0
PM2 | 2020-11-25T09:27:28: PM2 log: App [app:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-11-25T09:27:28: PM2 log: pid=1474 msg=process killed
PM2 | 2020-11-25T09:28:23: PM2 log: App [app:0] starting in -fork mode-
PM2 | 2020-11-25T09:28:23: PM2 log: App [app:0] online
/root/.pm2/logs/app-error.log last 15 lines:
/root/.pm2/logs/app-out.log last 15 lines:
0|app | [ERR] /event?pagesize=30&lasttime=1556740526369 { status: 301, body: { msg: null, code: 301 } }
0|app | [OK] /search?keywords=海阔天空
0|app | [OK] /comment/music?id=186016&limit=1
0|app | [OK] /dj/program?rid=336355127
0|app | [ERR] /playlist/create {
0|app | status: 500,
0|app | body: { code: 500, message: null, debugInfo: null, msg: null }
0|app | }
0|app | [ERR] /playlist/create {
0|app | status: 500,
0|app | body: { code: 500, message: null, debugInfo: null, msg: null }
0|app | }
0|app | [OK] /top/song?type=96
0|app | [OK] /top/song?type=96
0|app | server running @ http://localhost:3080
|
现在我们的项目是运行在服务器后台,我们现在要做的是讲其映射到我们的公网,使用我们 # 修改nginx 配置文件
>cd /etc/nginx
# 使用 vim 工具将我们文件打开编辑
>vim nginx.conf
http {
# ... 省略其他配置代码
# 配置我们的 nginx 如下
server {
listen 3030;
server_name localhost;
#location / {
# root html;
# index index.html index.htm;
#}
# 匹配接口地址是以 /api开头,继续向下匹配
location ~ {
proxy_pass http://127.0.0.1:3080;
}
}
}
# 配置好了,现在保存退出 `wq`
# 检查我们的 nginx 配置是否存在书写上的问题
>nginx -t -c nginx.conf
# 检查无误后,重新启动我们的 nginx 服务
# 停止 nginx 服务
>systemctl stop nginx
# 启动 nginx 服务
>systemctl start nginx
|
现在我们可以访问我们项目了, 愉快的玩耍~ > http://39.99.241.232:3030/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Centos7
安装Nginx
请查考 网上的教程,这里不做详述。The text was updated successfully, but these errors were encountered: