目录
一、要求
1.配置不同IP访问
2.配置不同端口访问
3.配置域名访问
二、前期准备
1.安装gcc g++的依赖库
2.安装 pcre的依赖库
3.安装zlib的依赖库
4.安装openssl的依赖库
5.解压nginx的安装包
6.进入到解压的nginx安装目录里面
7.将nginx安装到/usr/local/下
8.编译
9.进入到nginx的安装目录
10.进入到nginx的sbin模块,并且启动nginx
11.查看启动是否成功
三、配置nginx
1.配置两个网卡(192.168.191.100和192.168.191.200)
2.启动ens33网卡
3.进入 /usr/local/nginx/html/配置我们的网页内容
4.创建文件
5.在文件下创建相关文件
6.配置虚拟主机文件,进入到/usr/local/nginx/conf/
7.编辑nginx.conf文件
8.编辑以下内容
9.保存退出
10.配置虚拟机本地host文件
11.编辑以下内容
12.配置本机(windows 10)host文件 (C:\Windows\System32\drivers\etc的host文件)
13.启动nginx
四、测试
基于ip
基于端口
基于域名
五、总结
yum -y install gcc gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
tar -zxvf nginx-1.24.0.tar.gz
cd nginx-1.24.0/
./configure --prefix=/usr/local/
make
make install
cd /usr/local/nginx
cd sbin/
./nginx
ps -ef | grep nginx
nmcli connection modify ens33 +ipv4.addresses 192.168.191.100/24
nmcli connection modify ens33 +ipv4.addresses 192.168.191.200/24
nmcli connection up ens33
cd /usr/local/nginx/html/
make ip
make name
make port
cd /usr/local/nginx/conf
vim nginx.conf
# ip 100
server {
listen 80;
server_name 192.168.191.100;
location / {
root /usr/local/nginx/html/ip/100;
index index.html;
}
}
# ip 200
server {
listen 80;
server_name 192.168.191.200;
location / {
root /usr/local/nginx/html/ip/200;
index index.html;
}
}
# port 100
server {
listen 100;
server_name 192.168.191.129;
location / {
root /usr/local/nginx/html/port/100;
index index.html;
}
}
# port 200
server {
listen 200;
server_name 192.168.191.129;
location / {
root /usr/local/nginx/html/port/200;
index index.html;
}
}
# www.jiege.com
server {
listen 80;
server_name www.jiege.com;
location / {
root /usr/local/nginx/html/name/jiege;
index index.html;
}
}
vim /etc/hosts
192.168.191.129 www.jiege.com
192.168.191.129 www.jiege.com
/usr/local/nginx/sbin/./nginx
在ubuntu下安装nginx也是同样的配置