一、要求
1.配置不同IP访问
2.配置不同端口访问
3.配置域名访问
二、前期准备
1.安装gcc g++的依赖库
1 | yum -y install gcc gcc-c++ |
2.安装 pcre的依赖库
1 | yum -y install pcre pcre-devel |
3.安装zlib的依赖库
1 | yum -y install zlib zlib-devel |
4.安装openssl的依赖库
1 | yum -y install openssl openssl-devel |
5.解压nginx的安装包
1 | tar -zxvf nginx-1.24.0.tar.gz |
6.进入到解压的nginx安装目录里面
1 | cd nginx-1.24.0/ |
7.将nginx安装到/usr/local/下
1 | ./configure --prefix=/usr/local/ |
8.编译
1 | make |
1 | make install |
9.进入到nginx的安装目录
1 | cd /usr/local/nginx |
10.进入到nginx的sbin模块,并且启动nginx
1 2 | cd sbin/ ./nginx |
11.查看启动是否成功
1 | ps -ef | grep nginx |
三、配置nginx
1.配置两个网卡(192.168.191.100和192.168.191.200)
1 2 | nmcli connection modify ens33 +ipv4.addresses 192.168.191.100/24 nmcli connection modify ens33 +ipv4.addresses 192.168.191.200/24 |
2.启动ens33网卡
1 | nmcli connection up ens33 |
3.进入 /usr/local/nginx/html/配置我们的网页内容
1 | cd /usr/local/nginx/html/ |
4.创建文件
1 2 3 | make ip make name make port |
5.在文件下创建相关文件
6.配置虚拟主机文件,进入到/usr/local/nginx/conf/
1 | cd /usr/local/nginx/conf |
7.编辑nginx.conf文件
1 | vim nginx.conf |
8.编辑以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # 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; } } |
9.保存退出
10.配置虚拟机本地host文件
1 | vim /etc/hosts |
11.编辑以下内容
1 | 192.168.191.129 www.jiege.com |
12.配置本机(windows 10)host文件 (C:WindowsSystem32driversetc的host文件)
1 | 192.168.191.129 www.jiege.com |
13.启动nginx
1 | /usr/local/nginx/sbin/./nginx |
四、测试
基于ip
基于端口
基于域名
五、总结
在ubuntu下安装nginx也是同样的配置
到此这篇关于nginx启动、配置及测试的文章就介绍到这了,更多相关nginx启动、配置、测试内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!