全部任务流程图
1.编辑hosts文件(实现本机的ip与域名映射)
如果在本机进行业务测试. 则windows/Linux系统,提供了一个测试的文件.在该文件中可以编辑域名与IP的映射关系. 但是只对本机有效. 该文件就是hosts文件.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost
::1 localhost
#图片服务器域名
#127.0.0.1 image.jt.com
#前端域名地址
#127.0.0.1 web.jt.com
#后端域名地址
#127.0.0.1 manage.jt.com#Linux系统配置 只对本机测试有效
192.168.126.129 image.jt.com
192.168.126.129 web.jt.com
192.168.126.129 manage.jt.com
2.Linux安装Nginx
下载地址
URL:http://nginx.org/en/download.html
上传压缩包
上传到指定目录中 /usr/local/src
操作安装包-Nginx数据源
解压:tar -xvf nginx补全名称
删除压缩包 rm -f nginx补全名称
重名称文件: mv nginx-1.19.4 nginx-source
3.安装nginx服务器
*说明:在nginx-source的根目录中执行如下命令
需要提前安装nginx的依赖项*
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
./configure
执行make
执行make install
查找Nginx真实文件地址:whereis nginx
nginx命令
1.启动命令: ./nginx
2.重启命令: ./nginx -s reload
3.关闭命令: ./nginx -s stop
配置Nginx配置文件(/usr/local/nginx/conf)
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#每个服务都是一个server
server {
#默认监听80端口
listen 80;
#监听域名信息
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#具体反向代理服务 / 默认写法
location / {
#root 代理的是一个目录
root html;
#默认访问页面
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#配置前端服务器
server {
listen 80;
server_name web.jt.com;
location / {
root dist;
index index.html;
}
}
#一次请求,访问一个服务器 集群的配置 负载均衡机制
# upstream 集群的关键字.
# tomcats 是集群的名称 可以任意 xxxx
# server 每个服务的地址
# 默认采用轮询的策略,依次访问服务器.
upstream tomcats {
server 192.168.126.129:8091;
server 192.168.126.129:8092;
}
#配置后端服务器 8091/8092
#后端域名 manage.jt.com
server {
listen 80;
server_name manage.jt.com;
location / {
#proxy_pass 反向代理服务器发起是一个http请求
proxy_pass http://tomcats;
}
}
#配置图片反向代理 image.jt.com
server {
listen 80;
server_name image.jt.com;
location / {
root /usr/local/src/images;
}
}
}
4.打包前端代码
修改前端对后台axios访问地址
修改图片上传访问axios访问地址
前端打包
vue脚手架中build生成dist静态资源
说明: 将前端打包好的目录dist 上传到指定的位置 /usr/local/nginx 目录下, 如图所示;