Linux 版本为 centos7html
首先直接使用 yum 安装node
$ yum -y install nodejs
复制代码
可是此时并非最新的版本, 应该是6.xxx,可使用 node -v
查看;nginx
首先安装 n(nodejs 管理工具)c++
$ npm install -g n
复制代码
安装完成后安装 node.js 最新版本mongodb
$ n latest
复制代码
而后使用npm
$ n
复制代码
选择最新版本。vim
接着全局改变 nodejs 版本centos
$ vim ~/.bash_profile
复制代码
并在其中输入安全
export N_PREFIX=/usr/local #node实际安装位置
export PATH=$N_PREFIX/bin:$PATH
复制代码
保存并退出,在用下面命令刷新bash
$ source ~/.bash_profile
复制代码
这边就升级成功了,再检查下版本吧。
首先编写 yum 库文件
$ sudo vi /etc/yum.repos.d/mongodb-org.repo
复制代码
将下面文本写入
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
复制代码
保存并退出;
检查可用库:
$ yum repolist
复制代码
若是看到
. . .
repo id repo name
mongodb-org-3.2/7/x86_64 MongoDB Repository
. . .
复制代码
就能够进行安装操做
$ sudo yum install mongodb-org
复制代码
安装结束后,启动它
$ sudo systemctl start mongod
复制代码
前期准备
$ yum install gcc-c++
$ yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
复制代码
安装结束后,执行安装 Nginx 的命令:
$ yum install nginx -y
复制代码
进入 nginx 文件夹
$ cd /etc/nginx
复制代码
打开配置文件:
$ vim nginx.conf
复制代码
忽略其余,咱们看 server, 删除多余的,将 server 改形成下面这样:
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
复制代码
而后咱们新增本身的代理配置,相似于下面:
server {
listen 80;
server_name xxx.com www.xxx.top;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
}
复制代码
解释下:
其余的照着写就👌, 上面文本达成的效果是,使用 server_name 代替直接访问 ip.
Ps. server_name 只能填写域名解析后的域名,而且须要在云服务器安全组中添加 80 端口的支持规则。
首先要申请证书,而且下载到本地。
一般它们会是这样命名:
// xxx 是域名
cert-1541562634350_xxx.crt
cert-1541562634350_xxx.key
复制代码
下载完后,使用 FTP 等同类工具上传到云服务器上,在 /etc/nginx 文件夹下建立 cert,将这这两个文件移到这个文件夹下;
接着编写 nginx.conf
server {
listen 443 ssl;
server_name *.xxx.com;
root /usr/share/nginx/html;
ssl_certificate /etc/nginx/cert/cert-1541562634350_www.funnyfm.top.crt;
ssl_certificate_key /etc/nginx/cert/cert-1541562634350_www.funnyfm.top.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
复制代码
几个注意点:
编写结束后,须要重启 Nginx
$ nginx -s reload
复制代码
好了,如今可使用 xxx.com
来代替直接访问 ip 了。