7.31(基于域名和IP地址的主机,上线商城)

将原有的nginx.conf文件备份

[root@tomcat ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
[root@tomcat ~]# grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf > /usr/local/nginx/conf/nginx.conf

一、基于域名的虚拟主机
创建项目,用于部署在nginx中发布到文本

1、编辑配置文件
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf

2、创建新的目录
[root@tomcat ~]# mkdir /abc

3、在/abc/目录下创建一个index.html
[root@tomcat ~]# echo "hello, i am abc" > /abc/index.html
[root@tomcat ~]# cat /abc/index.html
hello, i am abc

4、将/abc/目录中的资源发布
1. 配置nginx.conf文件
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf

[root@tomcat ~]# /usr/local/nginx/sbin/nginx

2. 主机劫持ip地址
[root@tomcat ~]# vim /etc/hosts

二、基于IP地址的虚拟主机
1、将之前配置的server模块保存到新的文件中
[root@tomcat ~]# sed -n '34,42p' /usr/local/nginx/conf/nginx.conf
[root@tomcat ~]# mkdir /usr/local/nginx/conf.d/
[root@tomcat ~]# sed -n '34,42p' /usr/local/nginx/conf/nginx.conf > /usr/local/nginx/conf.d/abc.conf
[root@tomcat ~]# cat /usr/local/nginx/conf.d/abc.conf 

[root@tomcat ~]# sed -i '34,42d' /usr/local/nginx/conf/nginx.conf

2、修改配置文件
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf

[root@tomcat ~]# /usr/local/nginx/sbin/nginx -s reload

3、使用ip地址访问不同的虚拟主机
1. 查看当前主机的物理网卡ip

[root@tomcat ~]# ifconfig ens33

2. 添加
[root@tomcat ~]# ifconfig ens33:1 192.168.8.129

3. 修改配置文件
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf

[root@tomcat ~]# vim /usr/local/nginx/conf.d/abc.conf 

4、基于端口的虚拟机的配置
不同端口访问不同项目

[root@tomcat ~]# vim /usr/local/nginx/conf.d/abc.conf 

[root@tomcat ~]# /usr/local/nginx/sbin/nginx -s reload

三、上线商城系统
生成一个,发布到nginx中 nodejs 安装npm 添加vue模块,使用vue创建vue3项目,构建静态资源,将静态资源添加到nginx项目

1、检查是否安装了epel 
[root@tomcat ~]# yum list installed | grep epel
[root@tomcat ~]# yum -y install epel-release

2、安装nodejs
[root@tomcat ~]# yum -y install nodejs

3、安装npm
[root@tomcat ~]# yum -y install npm
[root@tomcat ~]# npm -v
8.19.4

4、安装vue
[root@tomcat ~]# npm config set registry https://registry.npmmirror.com
[root@tomcat ~]# npm install @vue/cli

[root@tomcat ~]# find / -name "vue"
/root/node_modules/vue
/root/node_modules/.bin/vue
[root@tomcat ~]# ls -l /root/node_modules/.bin/vue

[root@tomcat ~]# /root/node_modules/.bin/vue -V
@vue/cli 5.0.8

5、创建vue项目
[root@tomcat ~]# /root/node_modules/.bin/vue create eleme_web

[root@tomcat ~]# cd eleme_web
[root@tomcat eleme_web]# npm run serve

[root@tomcat eleme_web]# nohup npm run serve&

[root@tomcat eleme_web]# yum -y install samba

6、编辑配置文件
[root@tomcat eleme_web]# vim /etc/samba/smb.conf


 
7、创建用户
[root@tomcat eleme_web]# useradd vueediter
[root@tomcat eleme_web]# smbpasswd -a vueediter
New SMB password:   123
Retype new SMB password:  123
Added user vueediter.

8、为该用户在文件夹中添加读写权限
[root@tomcat eleme_web]# setfacl -m u:vueediter:rwx /root/eleme_web/

9、启动服务
[root@tomcat eleme_web]# systemctl start nmb
[root@tomcat eleme_web]# systemctl start smb

 10、创建文件夹
[root@tomcat eleme_web]# mkdir public/img
[root@tomcat eleme_web]# mkdir public/video
[root@tomcat eleme_web]# mkdir public/music

11、部署nfs服务器
1. 安装
[root@elemestatic ~]# yum -y install rpcbind.x86_64
[root@elemestatic ~]# yum -y install nfs-utils.x86_64 

2. 修改配置文件
[root@elemestatic ~]# vim /etc/exports

[root@elemestatic ~]# mkdir -p /static/img/

3. 启动服务
[root@elemestatic ~]# systemctl start rpcbind.service 
[root@elemestatic ~]# systemctl start nfs
[root@elemestatic ~]# netstat -lnput | grep nfs
[root@elemestatic ~]# netstat -lnput | grep rpc

4. 另一台安装并挂载
[root@tomcat eleme_web]# yum -y install nfs-utils.x86_64 

[root@tomcat eleme_web]# mount -t nfs 192.168.8.136:/static/img public/img/

[root@tomcat src]# cd components/
[root@tomcat components]# ls
HelloWorld.vue
[root@tomcat components]# vim HelloWorld.vue

[root@tomcat src]# ls views/

[root@tomcat src]# vim views/HomeView.vue

[root@tomcat eleme_web]#nohup npm run serve&

  • 23
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值