吴旭华 发表于 2024-6-22 13:04:51

nginx启动、配置、测试(全网最全)

目录

一、要求
        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
基于端口
基于域名
 五、总结

一、要求

        1.配置差异IP访问

        2.配置差异端口访问

        3.配置域名访问

二、前期准备

        1.安装gcc g++的依靠库

   yum -y install gcc gcc-c++
 https://img-blog.csdnimg.cn/6b28cf47dd9d443aaca80c1e9a12f0e3.png
         2.安装 pcre的依靠库

   yum -y install pcre pcre-devel
https://img-blog.csdnimg.cn/1586c6077b0649f2bc85126a591ed435.png
        3.安装zlib的依靠库

    yum -y install zlib zlib-devel
 https://img-blog.csdnimg.cn/9d7e38b546744a1ea6ff09638101f8b3.png 
           4.安装openssl的依靠库

   yum -y install openssl openssl-devel
https://img-blog.csdnimg.cn/f4370d6dc6704091a4130ed5451c927a.png
         5.解压nginx的安装包

   tar -zxvf nginx-1.24.0.tar.gz
https://img-blog.csdnimg.cn/97c00eb1ffe54fdc8968054488fbac0f.png
        6.进入到解压的nginx安装目录里面

   cd nginx-1.24.0/
https://img-blog.csdnimg.cn/b3c7ee15c1cc42eea321175c3cfa2908.png
        7.将nginx安装到/usr/local/下

   ./configure --prefix=/usr/local/
https://img-blog.csdnimg.cn/de2accbd7c074573b896c5bd1afc3fc9.png
         8.编译

   make
    make install
https://img-blog.csdnimg.cn/24c0e1f0aa23408dba3d96c88c163259.pnghttps://img-blog.csdnimg.cn/791983426f14492bbb180d505ddae78b.png
         9.进入到nginx的安装目录

   cd /usr/local/nginx
https://img-blog.csdnimg.cn/63323afe9ecc4991b77b11be0ae4c2c0.png
         10.进入到nginx的sbin模块,而且启动nginx

   cd sbin/
./nginx
https://img-blog.csdnimg.cn/1be62da6c516448b9ed27da6f4cecf0b.png
 11.查看启动是否乐成

   ps -ef | grep nginx
https://img-blog.csdnimg.cn/efac1ed23add4d3d8a7fb86fb9e1cefa.png
https://img-blog.csdnimg.cn/69f451d2574b462fb0c474e592837765.png

三、配置nginx

        1.配置两个网卡(192.168.191.100和192.168.191.200)

   nmcli connection modify ens33 +ipv4.addresses 192.168.191.100/24
nmcli connection modify ens33 +ipv4.addresses 192.168.191.200/24  
https://img-blog.csdnimg.cn/b7e8da13833a496fb1c8b27fe2d65452.png
          2.启动ens33网卡

   nmcli connection up ens33
https://img-blog.csdnimg.cn/1774d2db6aa342479285de8a0ef33a02.png
        3.进入 /usr/local/nginx/html/配置我们的网页内容

   cd /usr/local/nginx/html/
        4.创建文件

   make ip
make name
make port
https://img-blog.csdnimg.cn/56cde950624a410f99a62dbfac0b7800.png
        5.在文件下创建相关文件

https://img-blog.csdnimg.cn/f842cc8fe7fb46098c5c94c97be1b5ae.png
        6.配置虚拟主机文件,进入到/usr/local/nginx/conf/

   cd /usr/local/nginx/conf
https://img-blog.csdnimg.cn/5cf7de5a47c643fc99e9143508ada8ee.png
        7.编辑nginx.conf文件

   vim nginx.conf
https://img-blog.csdnimg.cn/b626f9b28cff454dba62b8daf4d9ee5c.png
        8.编辑以下内容

     # 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;
        }
    }
https://img-blog.csdnimg.cn/70c9cd52787241c8bc2dd8ff47caefe3.png
        9.生存退出

        10.配置虚拟机本地host文件

   vim /etc/hosts
https://img-blog.csdnimg.cn/0103f732666241a1819740ead24fea39.png
        11.编辑以下内容

   192.168.191.129 www.jiege.com
https://img-blog.csdnimg.cn/2429c8d56df1441fb57d5a69df41023a.png
        12.配置本机(windows 10)host文件 (C:\Windows\System32\drivers\etc的host文件)

   192.168.191.129 www.jiege.com
https://img-blog.csdnimg.cn/59abe8bf8dc44e048906d6ab44c90838.png
        13.启动nginx

   /usr/local/nginx/sbin/./nginx 
https://img-blog.csdnimg.cn/304fe55362174853a4607d867c64b556.png
https://img-blog.csdnimg.cn/b7761c56f09d41f594ab7b9178c45bf0.png
四、测试

基于ip

https://img-blog.csdnimg.cn/5127012415f148d5a5d43e3275992dd4.pnghttps://img-blog.csdnimg.cn/0b6508972bbe4386bcb8bd9f3e3750c1.png
基于端口

https://img-blog.csdnimg.cn/e1e797fc6bf54f9aad1a78ddb45ef4f7.pnghttps://img-blog.csdnimg.cn/9a1d0468654b49499f0adf438da52257.png
基于域名

https://img-blog.csdnimg.cn/5cc2735f4cca4f5da21bbec68499bbbc.png
 五、总结

        在ubuntu下安装nginx也是同样的配置


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: nginx启动、配置、测试(全网最全)