1. 项目打包
npm run build
2. 将build 出来的文件放到服务器一路径下
scp -r build root@47.93.XX.X:/home/site
3. 配置nginx
mkdir /etc/nginx/sitehost
cd /etc/nginx/sitehost && touch sitehosts.conf
vim sitehosts.conf
输入以下内容
server {
listen 8888; # 端口号
server_name localhost;
root /home/site/; #项目服务器路径
location / {
try_files $uri @fallback;
}
location @fallback {
rewrite .* /index.html break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
将上述的配置写到nginx.conf 文件中
vim /etc/nginx/nginx.conf
http {
include /etc/nginx/sitehost/*.conf; #主要写这一行
include mime.types;
...
server {
....
}
...
}
4. 重启nginx
ps -ef | grep nginx
kill -9 nginx 主端口号 # 杀掉 nginx端口号
nginx # 启动nginx
这时在浏览器输入你服务器ip加端口号就可以了。
查看哪些端口已被占用:
netstat -ant|grep LISTEN