(1)购买服务器
阿里云,腾讯云等。
(2)安装xshell和xftp。(操作云服务器)。
(3)安装nginx
1、切换到对应路径(ls可以查看当前路径下的所有下一级文件)
cd /
cd etc
2、安装nginx
yum install nginx
(这一步完成后,浏览器打开服务器ip地址,可以看到nginx的默认界面)
(4)配置nginx.conf文件
(1)location / {
root /root/www/dist(项目文件地址)
index index.html(默认界面)
}
(2)location /api {
proxy_pass http://127.0.0.1
}
备注:我是请求api时,调用了别的服务器的数据,所以要写这个,如果你的项目没有,可以不用写)
/api 当你访问的路径起始是/api
(127.0.0.1是要访问的服务器地址)
(3)user nginx 改为 user root;(root为主机名,linux是root)
(4)注释掉部分代码
1、include /etc/nginx/conf.d/*.conf;
2、include /etc/nginx/default.d/*.conf;
(5)测试nginx.conf文件是否正确
nginx -t
(6)重启nginx
service nginx restart
(7)浏览器打开服务器ip地址就可以看到你写的项目了。