一、基于域名配置server
1. 一个配置文件一般只有一个 http 模块
2. 一个 http 模块可以有多个 server 模块
3. 一个 server 模块就是一套 web 项目
4. 一个 server 模块中可以有多个 location
5. location 就是项目中的 url 路由
# 第一步
mkdir /zhangmin
# 第二部
echo "i am zhangmin" > /zhangmin/index.html
# 第三步
vim /usr/local/nginx/conf/nginx.conf
# 第三步
http{
server{
listen 80 ;
root /zhangmin;
server_name www.zhangmin.com;
location /{
index index.html;
}
}
server{...}
}
# 第四步
vim /etc/hosts
######################
10 .1.1.10 www.zhangmin.com
########################
curl www.zhangmin.com
一个 nginx 服务器中有多个 server 的时候是非常难于管理的,我们会将每一个server 单独创建一个文件保存,在主配置文件使用 include
mkdir /usr/local/nginx/conf.d/
touch /usr/local/nginx/conf.d/zhangmin.conf
sed -n 'server 的行号 p' /usr/local/nginx/conf/nginx.conf > ..../zhangmin.conf
sed -i 'server 的行号 d' /usr/local/nginx/conf/nginx.conf
vim /usr/local/nginx/conf/nginx.conf
================
include /usr/local/nginx/conf.d/*.conf
/usr/local/nginx/sbin/nginx -s rdlaod
二、基于ip配置server
为网卡添加一个新的 ip 地址
ifconfig ens33:1 10.1.1.11
server{
listen 80;
server_name 10.1.1.10;
root /zhangmin;
location /{
index index.html;
}
}
server{
listen 80;
servername 10.1.1.11;
root html;
location /{
index index.html;
}
基于端口配置 server 80,可以省略,一般来说基于端口的配置,用于企业内部的项目测试
server{
listen 80;
server_name 10.1.1.10;
.....
}
server{
listen 8080;
server_name 10.1.1.10;
.....
}
systemctl stop firewalld
firelwall-cmd --zone=public --add-ports=8080/tcp --permament && firewall-cmd --reload;
三、部署一个nodejs项目
1、装包
第一台主机
[root@zhu ~]# yum list installed | grep epel
epel-release.noarch 7-11 @extras
[root@zhu ~]# yum -y install nodejs
[root@zhu ~]# node -v
v16.20.2
[root@zhu ~]# yum -y install npm
[root@zhu ~]# npm -v
8.19.4
2、创建eleme项目
[root@zhu ~]# npm config set registry https://registry.npmmirror.com
[root@zhu ~]# npm install @vue/cli
[root@zhu ~]# find / -name "vue"
/root/node_modules/vue
/root/node_modules/.bin/vue
[root@zhu ~]# ls -l /root/node_modules/.bin/vue
lrwxrwxrwx. 1 root root 22 7月 31 14:47 /root/node_modules/.bin/vue -> ../@vue/cli/bin/vue.js
[root@zhu ~]# /root/node_modules/.bin/vue -V
@vue/cli 5.0.8
3、创建vue项目
[root@zhu ~]# /root/node_modules/.bin/vue create eleme_web
[root@zhu ~]# cd /root/eleme_web/
4、将eleme项目使用samba共享
[root@zhu eleme_web]# yum -y install samba
[root@zhu eleme_web]# pwd
/root/eleme_web
[root@zhu eleme_web]# vim /etc/samba/smb.conf
……
[eleme_web]
comment = daning
path = /root/eleme_web
guest ok = no
writable = yes
[root@zhu eleme_web]# useradd vueediter
[root@zhu eleme_web]# smbpasswd -a vueediter
New SMB password:
Retype new SMB password:
Added user vueediter.
[root@zhu eleme_web]# setfacl -m u:vueediter:rwx /root/eleme_web/
[root@zhu eleme_web]# systemctl restart nmb.service
[root@zhu eleme_web]# systemctl restart smb.service
[root@zhu eleme_web]# mkdir public/img
[root@zhu eleme_web]# mkdir public/video
[root@zhu eleme_web]# mkdir public/music
[root@zhu eleme_web]# tree public/
public/
├── favicon.ico
├── img
├── index.html
├── music
└── video
3 directories, 2 files
[root@zhu eleme_web]#
[root@zhu eleme_web]# yum -y install nfs-utils.x86_64 nfs4-acl-tools.x86_64
[root@zhu eleme_web]# mount -t nfs 192.168.110.21:/static/img public/img/
第二台主机
[root@cong ~]# vim /etc/exports
/static/img *(rw,sync)
[root@cong ~]# mkdir -p /static/img/
[root@cong ~]# systemctl restart rpcbind.service
[root@cong ~]# systemctl restart nfs
[root@cong ~]# netstat -lnput | grep rpcbind
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1797/rpcbind
tcp6 0 0 :::111 :::* LISTEN 1797/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 1797/rpcbind
udp 0 0 0.0.0.0:700 0.0.0.0:* 1797/rpcbind
udp6 0 0 :::111 :::* 1797/rpcbind
udp6 0 0 :::700 :::* 1797/rpcbind