# 1. 因为我用的服务器是华为的
# centOS7.5 搭建 nginx 服务器
# 通过 MSTSC 远程连接
重启服务器
./nginx -s reload
启动命令
./nginx
# 一、搭建 nginx 服务器
-
在搭建 nginx 服务器之前,我们需要先购买一台云服务器
-
安装一个连接云服务器的客服端
# 1.1 登录腾讯云的控制台
# 1.2 修改服务器的密码
密码为: GXqwe232187
# 1.3 在本地客户端连接远程的电脑 (服务器)
xshell
# 1.4 搭建 nginx 服务器
# 1.4.1 如果是一台新的服务器或者说是第一次安装 nginx, 那我们需要先安装安装 gcc (编辑器)
# 1.4.2 检测 gcc 是否安装成功
# 1.4.3 安装 PCRE(正则表达式库)
1
| yum install -y pcre pcre-devel
|
# 1.4.4 安装 zlib(压缩库)
1
| yum install -y zlib zlib-devel
|
# 1.4.5 安装 openssl(密码库)
1
| yum install -y openssl openssl-devel
|
# 1.4.6 下载 nginx 的安装包
1 2 3
| 先cd到 usr/local/src目录下面
wget http://nginx.org/download/nginx-1.16.1.tar.gz
|
# 1.4.7 解压 nginx 安装包
1
| tar zxvf nginx-1.16.1.tar.gz
|
# 1.4.8 进入解压之后的安装包目录 (进入 nginx 的目录)
# 1.4.9 安装 nginx 所需要的一些依赖
1
| ./configure && make && make install
|
# 1.4.10 查看 nginx 安装的目录
# 1.4.11 启动 nginx 服务器
1 2 3 4
| cd /usr/local/nginx/sbin
//启动命令 ./nginx
|
# 1.4.12 查看 nginx 是否跑起来,可以通过查看进程看 nginx 是否运行起来
1 2 3 4 5 6
| ps -ef | grep nginx
//如果显示以下信息,则表示nginx已经跑起来了 root 7362 1 0 10:56 ? 00:00:00 nginx: master process ./nginx nobody 7363 7362 0 10:56 ? 00:00:00 nginx: worker process root 7494 1912 0 10:57 pts/0 00:00:00 grep --color=auto nginx
|
# 1.4.13 通过服务器 ip 验证
1 2 3 4
| cd /usr/local/nginx/conf 目录下,可以看到有nginx.conf这个文件,我们需要对它进行修改,把ip设置成我们自己的ip
通过vim编辑器打开nginx.conf这个文件 -> 按下 i 键就可以进行输入 -> 将第一行的no body改为 root, 将server 下面的server_name 的localhost 改为自己服务器的ip地址 -> 按esc推出键,然后输入:wq
|
# 1.4.14 重启 nginx 服务器,让修改的配置文件生效
1 2 3 4
| cd 到 /usr/local/nginx/sbin
//重启服务器 ./nginx -s reload
|
# 二、将 vue 的项目上传到 nginx
nginx 默认加载的是那个目录呢?
默认加载的是 html 这个目录
# 2.1 下载 ftp 工具,(文件传输协议)
1
| https://softdown.zol.com.cn/detail/37/366793.shtml
|
# 2.2 进入 html 目录
1
| cd /usr/local/nginx/html
|
# 2.3 将 html 文件的内容可以删掉
# 2.4 将 vue 打包之后的内容上传到 nginx 的 html 目录里面
# 2.5 通过访问当前服务器的 ip 地址,就可以访问到我们上传的项目
# 三、配置 nginx 跨域问题
# 3.1 修改 nginx.conf 这个文件
1 2 3
| location /pro-api{ proxy_pass http://mengxuegu.com:9999/pro-api; }
|