如何在一个pure aliyun server 上搭建node环境

227 阅读1分钟

1.install node

1.1 wget https://nodejs.org/dist/v10.5.0/node-v10.5.0.tar.gz
1.2 tar xzvf node-v* && cd node-v*
1.3 sudo yum install gcc gcc-c++
1.4 ./configure
1.5 make
1.6 sudo make install

以上为下载源文件自己编译的模式,比较复杂,有可能会出错,可以直接使用一下的命令

yum install nodejs

2.install pm2

npm i -g pm2

3.reset git project

-- Remove the history from 
rm -rf .git

-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"

-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
git push -u --force origin master

4.install git

sudo yum install git

5.clone project

ssh-keygen -t rsa -C "email address"
touch config
vi config
Host gitee.com
 IdentityFile ~/.ssh/sshname

6.install mongodb

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
sudo yum install mongodb-org
sudo systemctl start mongod

https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-centos-7

7.install nginx

sudo yum install nginx

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

8.修改nginx默认的端口

vi /etc/nginx/nginx.conf
80 to other port

9.踩坑点

1.阿里云默认没开端口,需要配置规则 2.阿里云配置规则之后,需要开启端口

firewall-cmd --zone=public --add-port=3000/tcp --permanent

3.解决react刷新时报404的问题 try_files $uri /index.html;

server {
        listen       80;
        server_name domain;
	charset utf-8;
	location / {
		autoindex on;
		try_files $uri /index.html;
		root filepath;
	}
}