2024年7月31日(基于域名和IP地址的虚拟机主机 上线静态商城)

1、将原有的nginx.conf文件备份

[root@static ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

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

2、基于域名的虚拟主机
(1)修改配置文件

[root@static ~]# vim /usr/local/nginx/conf/nginx.conf

(2)创建新的目录

[root@static ~]# mkdir /aaa

(3)在/aaa目录下创建index.html文件

[root@static ~]# echo "hello,I am aaa" > /aaa/index.html
[root@static ~]# cat /aaa/index.html 
hello,I am aaa

3、将/aaa目录中的资源发布
(1)配置nginx.conf文件

[root@static ~]# vim /usr/local/nginx/conf/nginx.conf

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

(2)主机劫持IP

[root@static ~]# vim /etc/hosts

 [root@static ~]# curl www.aaa.com
I am static server

 4、将刚才配置的server模块保存到一个新的文件中

[root@static ~]# mkdir /usr/local/nginx/conf.d/
[root@static ~]# sed -n '34,40p' /usr/local/nginx/conf/nginx.conf > /usr/local/nginx/conf.d/aaa.conf
[root@static ~]# cat /usr/local/nginx/conf.d/aaa.conf 
    server{
        listen    80;
        server_name    www.aaa.com;
        location / {
            index    index.html;
        }
    }
[root@static ~]# sed -i '34,40d' /usr/local/nginx/conf/nginx.conf

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

[root@static ~]# /usr/local/nginx/sbin/nginx -s reload
[root@static ~]# vim /usr/local/nginx/conf/nginx.conf


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

5、使用IP地址访问不同的虚拟主机
(1)创建新的IP挂载这个网卡上

[root@static ~]# ifconfig ens33:1 192.168.8.200

(2)修改配置文件

[root@static ~]# vim /usr/local/nginx/conf/nginx.conf


[root@static ~]# vim /usr/local/nginx/conf.d/aaa.conf


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

 [root@static ~]# vim /usr/local/nginx/conf.d/aaa.conf


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

6、上线一个静态的前端系统

生成一个,发布到nginx中

nodejs 安装npm 添加vue模块,使用vue创建vue3项目,构建静态资源,将静态资源添加到nginx项目中

(1)在安装nodejs之前检查是否安装epel

[root@static ~]# yum list installed | grep epel
[root@static ~]# yum -y install epel-release

(2)安装nodejs(是个运行环境)

[root@static ~]# yum -y install nodejs

[root@static ~]# node -v
v16.20.2

(3)安装npm(nodejs 的包管理器)

[root@static ~]# yum -y install npm
[root@static ~]# npm -v
8.19.4

(4)安装vue

[root@static ~]# npm config set registry https://registry.npmmirror.com

[root@static ~]# npm install @vue/cli 

[root@static ~]# find / -name "vue"
/root/node_modules/vue
/root/node_modules/.bin/vue

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

(4)创建vue项目

[root@static ~]# /root/node_modules/.bin/vue create eleme_web

 

[root@static ~]# cd eleme_web/
[root@static eleme_web]# npm run serve

[root@static eleme_web]# nohup npm run serve&
[1] 3130

[root@static eleme_web]# npm run serve

http://192.168.8.159:8082/

7、配置samba

[root@static eleme_web]# yum -y install samba
samba文件位置

(1)编辑配置文件

[root@static eleme_web]# pwd
/root/eleme_web
[root@static eleme_web]# vim /etc/samba/smb.conf

(2)创建用户

[root@static eleme_web]# useradd vueediter
[root@static eleme_web]# smbpasswd -a vueediter
New SMB password:123
Retype new SMB password:123
Added user vueediter.

 (3)为该用户在文件夹中添加读写权限

[root@static eleme_web]# setfacl -m u:vueediter:rwx /root/eleme_web/

(4)启动服务

[root@static eleme_web]# systemctl start nmb
[root@static eleme_web]# systemctl start smb

 

[root@static eleme_web]# mkdir public/img
[root@static eleme_web]# mkdir public/video
[root@static eleme_web]# mkdir public/music
[root@static eleme_web]# tree public/
public/
├── favicon.ico
├── img
├── index.html
├── music
└── video

 9、部署nfs服务器

[root@elemestatic ~]# yum -y install rpcbind.x86_64
[root@elemestatic ~]# yum -y install nfs-utils.x86_64

[root@elemestatic ~]# vim /etc/exports

/static/img     *{rw,sync}
[root@elemestatic ~]# mkdir -p /static/img/

[root@elemestatic ~]# systemctl start rpcbind
[root@elemestatic ~]# systemctl start nfs

[root@static eleme_web]# yum -y install nfs-utils.x86_64

[root@static eleme_web]# mount -t nfs 192.168.8.161:/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&

 

  • 20
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要为虚拟机配置静态IP地址,可以按照以下步骤进行操作: 1. 打开虚拟机管理软件,如VMware,点击编辑按钮打开虚拟网络编辑器。\[2\] 2. 在虚拟网络编辑器中,选择使用NAT模式的网卡,点击NAT设置按钮,查看虚拟机的网络配置。 3. 在显示的配置文件中,找到需要配置静态IP的网卡,编辑该网卡的配置信息。设置IP地址(与子网IP处于同一个网段)、子网掩码、网关和DNS地址等。\[2\] 4. 保存配置文件后,重启虚拟机的网络适配器,可以通过断开再连接网络适配器或者重启网络服务来实现。\[3\] 5. 最后,可以通过命令ip a来查看虚拟机的当前IP地址,确保静态IP地址配置成功。\[3\] 请注意,具体的操作步骤可能会因虚拟机管理软件的不同而有所差异,以上步骤仅供参考。在配置静态IP地址时,需要确保所设置的IP地址与子网IP处于同一个网段,并与网络环境中的网关和DNS地址保持一致。 #### 引用[.reference_title] - *1* *2* [虚拟机设置静态IP地址](https://blog.csdn.net/zyk1111/article/details/124548241)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [虚拟机配置静态ip地址](https://blog.csdn.net/weixin_46470342/article/details/105560562)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值