前期准备
1.服务器
一台Linux服务器(CentOS为例) window....
一款web服务器(Nginx为例) Apache/Tomcat....
2.域名
阿里云为例:https://www.aliyun.com/ 购买配置略
连接服务器
可以使用gitbash进行命令操作
1.连接到远程服务器 ssh user@remote_ip(例如:ssh root@192.168.0.1 服务器用户名:root 远程服务器的ip:192.168.0.1)
2.查看版本 uname -a
3.安装nginx yum install nginx
yum install nginx,安装会报下面的错。原因是nginx位于第三方的yum源里面,而不在centos官方yum源里面
解决方法:
安装
sudo yum install epel-release
更新(更新时间稍微长一些,耐心等待)
yum update
重新试一下:
yum install -y nginx
4.查看是否ok? nginx -V
5.nginx配置
(1)nginx -t找到nginx对应目录
(2)cd /etc/nginx
(3) vim nginx.conf (如果没有安装vim则需要安装 yum install vim)
(4)权限改为root user nginx改为user root
(5)找到http里面的server中的location 配置根 和 项目存放路径,以及首页为index
6.上传网站到服务器(也可以直接在指定目录下输入rz进行选择)
首先查看本地以及服务器是否安装了scp。输入scp即可看到。如果没有安装,则使用yum install openssh-client安装,因为openssh-client里面提供了scp工具
(1)上传scp -r local_dir user@ip:/remote_dir (local_dir文件夹路径 user服务器用户名 ip:/remote_dir远程服务器文件夹路径)
说明:demo文件夹下的所有 root用户名 远程服务器及文件夹路径47.94.255.230:/root/www
(2)查看是否真的上传成功
连接服务器 ssh root@47.94.255.230
切换到/root/www目录下 cd /root/www
查看是否已经ok ls
注:删除命令
rm -rf mydir /*删除mydir目录*/
ssh root@192.168.0.1 "rm -rf /home/tele/web/tele-beta/*" //删除/home/tele/web/tele-beta/下的所有文件
7.启动nginx
nginx -t 检查配置 以及是否成功
nginx -s reload重新启动nginx 然后就可以通过ip方式访问了。
8.域名访问(注:先备案,然后服务器跟域名信息必须要一致,比如说个人域名和企业服务器,这是完全不行的)
域名->选择对应的域名->解析->新手引导或者添加解析
或者