准备工作
需要购买一台服务器,买一个域名(这里使用的是华为云的域名)
因为域名解析需要用到服务器的ip地址,所以需要先购买服务器
服务器购买(选择最便宜的就好)
安装xshell和xftp(选择免费版的)
在xshell建立ssh连接
域名
如何购买域名以及解析域名
第一步:进入域名注册,这里我已经买好一个域名(买1块钱的那个就好,企业级的不要买,不能买),点击解析
第二步:点添加记录集,二级域名解析
域名解析完毕^_^
Nginx Web 服务器安装和启动
- 安装yum依赖
yum install yum-utils- cd /etc/yum.repos.d/
#添加nginx的yum源码
vim nginx.repo
添加配置信息到 nginx.repo 文件中
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/ r e l e a s e v e r / releasever/ releasever/basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
安装 Nginx
yum install nginx -y
启动nginx服务
/usr/sbin/nginx
Nginx 部署静态网站
1.在 /etc/nginx/目录下新建文件夹 vhosts
cd /etc/nginx/
mkdir vhosts
cd vhosts
vim fruitshop.cdggdc.cn.conf
2.新建自定义配置文件fruitshop.cdggdc.cn.conf
server {
listen 80;
server_name fruitshop.cdggdc.cn;
location / {
# 网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
# 例如,您的网站运行目录在/workspace/icoding下,则填写/workspace/icoding
root /workspace/icoding;
index index.html index.htm;
}
}
在/etc/nginx/nginx.conf 中的 http 模块底部引入以上新建的自定义配置文件 fruitshop.cdggdc.cn.conf
修改配置文件,要对配置文件备份
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
编辑 nginx.conf 配置文件
cd /etc/nginx/
vim nginx.conf
在 nginx.conf 文件中的引入自定义配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
# 导入自定义配置文件,用于配置我们自己的域名(导入的自定义配置文件是有先后顺序的)
include /etc/nginx/vhosts/*.conf;
}
检查是否存在语法错误
nginx -t
新建存放项目的目录/workspace/icoding
mkdir -p /workspace/icoding
跳转到对应目录,然后上传文件
cd /workspace/icoding
打开之后上传对应的文件就可以了
上传文件之后,需要重新加载
nginx -s reload
部署完毕^_^
再部署一个的操作:
1.再解析一个域名,然后在vhosts新建一个文件,如fangmi.cdggdc.cn.conf,文件内容如下:
注意:需要新建一个目录,/workspace/xiaomi
2.跳转到此目录,再上传文件,然后就可以了,(其他操作不需要)