本文主要是介绍linux同一台机器安装两台nginx,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一 nginx的依赖库的安装
1.1 nginx的概述说明
1.1.1 nginx的离线包
离线包的安装包见百度网盘: nginx的资料/xxx
1.1.2 nginx需要安装的插件
1.gcc ,gcc++
2.prce
3.openssl
4.zlib
5.nginx
二 nginx的安装
2.1 将nginx的所有插件包上传到服务器
通过sftp命令,将nginx的离线包上传到服务器上。
2.3 离线安装gcc,gcc++
[root@192 kecheng-software-packages]# ls -l total 1015928 -rw-r--r--. 1 root root 0 Feb 25 10:14 1.txt -rw-r--r--. 1 root root 0 Feb 25 10:14 aa -rw-r--r--. 1 root root 64246045 Mar 1 10:45 apache-activemq-5.16.1-bin.tar.gz -rw-r--r--. 1 root root 67938106 Feb 25 10:07 apache-flume-1.9.0-bin.tar.gz -rw-r--r--. 1 root root 9506321 Feb 26 10:09 apache-maven-3.6.3-bin.tar.gz -rw-r--r--. 1 root root 5977 Nov 21 2020 CrawerTest.java -rw-r--r--. 1 root root 55201623 Feb 25 10:07 kafka_2.12-2.1.0.tgz -rw-r--r--. 1 root root 84628399 Feb 26 10:10 kafka-eagle-bin-1.3.2.tar.gz -rw-r--r--. 1 root root 661214270 Nov 7 2020 mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -rw-r--r--. 1 root root 62506980 Jun 28 21:47 nginxOfflinePack.tar.gz -rw-r--r--. 1 root root 35042811 Feb 25 10:07 zookeeper-3.4.10.tar.gz |
#解压
[root@192 kecheng-software-packages]# tar -zxvf nginxOfflinePack.tar.gz -C /root/export/servers/ nginxOfflinePack/ nginxOfflinePack/cpp-4.8.5-36.el7_6.2.x86_64.rpm nginxOfflinePack/gcc-4.8.5-36.el7.x86_64.rpm nginxOfflinePack/gcc-c++-4.8.5-36.el7.x86_64.rpm nginxOfflinePack/glibc-2.17-260.el7.x86_64.rpm nginxOfflinePack/glibc-common-2.17-260.el7.x86_64.rpm nginxOfflinePack/glibc-devel-2.17-260.el7.x86_64.rpm nginxOfflinePack/glibc-headers-2.17-260.el7.x86_64.rpm nginxOfflinePack/glibc-static-2.17-260.el7.x86_64.rpm nginxOfflinePack/glibc-utils-2.17-260.el7.x86_64.rpm nginxOfflinePack/kernel-headers-3.10.0-957.el7.x86_64.rpm nginxOfflinePack/libmpc-1.0.1-3.el7.x86_64.rpm |
#首先cd到nginxOfflinePack目录下,然后运行命令:rpm -Uvh *.rpm --nodeps --force
[root@192 kecheng-software-packages]# cd /root/export/servers/nginxOfflinePack/ [root@192 nginxOfflinePack]# ls -l total 67920 -rwxrwxrwx. 1 root root 6228084 Jul 11 2019 cpp-4.8.5-36.el7_6.2.x86_64.rpm -rwxrwxrwx. 1 root root 16964548 Jul 10 2019 gcc-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 7534972 Jul 10 2019 gcc-c++-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 3804652 Jul 11 2019 glibc-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 12048264 Jul 11 2019 glibc-common-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1120792 Jul 11 2019 glibc-devel-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 699380 Jul 11 2019 glibc-headers-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1623236 Jul 11 2019 glibc-static-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 227192 Jul 11 2019 glibc-utils-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 8355364 Jul 11 2019 kernel-headers-3.10.0-957.el7.x86_64.rpm -rwxrwxrwx. 1 root root 51732 Jul 11 2019 libmpc-1.0.1-3.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1580028 Jul 10 2019 libstdc++-devel-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 208316 Jul 11 2019 mpfr-3.1.1-4.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1032345 Jul 11 2019 nginx-1.16.0.tar.gz -rwxrwxrwx. 1 root root 5348369 Jul 11 2019 openssl-1.0.2r.tar.gz -rwxrwxrwx. 1 root root 2085854 Jul 1 2019 pcre-8.43.tar.gz -rwxrwxrwx. 1 root root 607698 Jul 1 2019 zlib-1.2.11.tar.gz [root@192 nginxOfflinePack]# rpm -Uvh *.rpm --nodeps --force Preparing... ################################# [100%] Updating / installing... 1:glibc-common-2.17-260.el7 ################################# [ 7%] 2:glibc-2.17-260.el7 ################################# [ 13%] 3:mpfr-3.1.1-4.el7 ################################# [ 20%] 4:libmpc-1.0.1-3.el7 ################################# [ 27%] 5:libstdc++-devel-4.8.5-36.el7 ################################# [ 33%] 6:kernel-headers-3.10.0-957.el7 ################################# [ 40%] 7:glibc-headers-2.17-260.el7 ################################# [ 47%] 8:glibc-devel-2.17-260.el7 ################################# [ 53%] 9:gcc-4.8.5-36.el7 ################################# [ 60%] 10:gcc-c++-4.8.5-36.el7 ################################# [ 67%] 11:glibc-static-2.17-260.el7 ################################# [ 73%] 12:cpp-4.8.5-36.el7_6.2 ################################# [ 80%] 13:glibc-utils-2.17-260.el7 ################################# [ 87%] Cleaning up / removing... 14:glibc-common-2.17-222.el7 ################################# [ 93%] 15:glibc-2.17-222.el7 ################################# [100%] [root@192 nginxOfflinePack]# |
2.4 离线安装pcre
1.再次退到 nginxOfflinePack 这一层目录,解压pcre的tar包
[root@192 nginxOfflinePack]# tar -zxvf pcre-8.43.tar.gz [root@192 nginxOfflinePack]# cd pcre-8.43 pcre-8.43/ pcre-8.43/pcre_scanner.h pcre-8.43/LICENCE pcre-8.43/makevp_c.txt pcre-8.43/PrepareRelease pcre-8.43/RunTest.bat pcre-8.43/pcre16_study.c pcre-8.43/pcre16_chartables.c pcre-8.43/pcre_jit_test.c pcre-8.43/pcregexp.pas pcre-8.43/pcre32_chartables.c pcre-8.43/pcre_get.c [root@192 nginxOfflinePack]# cd pcre-8.43/ [root@192 pcre-8.43]# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk [root@192 pcre-8.43]# make rm -f pcre_chartables.c ln -s ./pcre_chartables.c.dist pcre_chartables.c make all-am make[1]: Entering directory `/root/export/servers/nginxOfflinePack/pcre-8.43' CC pcretest-pcretest.o CC pcretest-pcre_printint.o [root@192 pcre-8.43]# make install make install-am make[1]: Entering directory `/root/export/servers/nginxOfflinePack/pcre-8.43' make[2]: Entering directory `/root/export/servers/nginxOfflinePack/pcre-8.43' /usr/bin/mkdir -p '/usr/local/lib' /bin/sh ./libtool --mode=install /usr/bin/install -c libpcre.la libpcreposix.la libpcrecpp.la '/usr/local/lib' |
2.5 离线安装openssl
再次退到 nginxOfflinePack 这一层目录,进入nginxOfflinePack这个安装包的目录下,进行解压此目录
[root@192 nginxOfflinePack]# ls -l total 67936 -rwxrwxrwx. 1 root root 6228084 Jul 11 2019 cpp-4.8.5-36.el7_6.2.x86_64.rpm -rwxrwxrwx. 1 root root 16964548 Jul 10 2019 gcc-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 7534972 Jul 10 2019 gcc-c++-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 3804652 Jul 11 2019 glibc-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 12048264 Jul 11 2019 glibc-common-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1120792 Jul 11 2019 glibc-devel-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 699380 Jul 11 2019 glibc-headers-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1623236 Jul 11 2019 glibc-static-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 227192 Jul 11 2019 glibc-utils-2.17-260.el7.x86_64.rpm -rwxrwxrwx. 1 root root 8355364 Jul 11 2019 kernel-headers-3.10.0-957.el7.x86_64.rpm -rwxrwxrwx. 1 root root 51732 Jul 11 2019 libmpc-1.0.1-3.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1580028 Jul 10 2019 libstdc++-devel-4.8.5-36.el7.x86_64.rpm -rwxrwxrwx. 1 root root 208316 Jul 11 2019 mpfr-3.1.1-4.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1032345 Jul 11 2019 nginx-1.16.0.tar.gz -rwxrwxrwx. 1 root root 5348369 Jul 11 2019 openssl-1.0.2r.tar.gz drwxr-xr-x. 9 1169 1169 12288 Jun 28 22:02 pcre-8.43 -rwxrwxrwx. 1 root root 2085854 Jul 1 2019 pcre-8.43.tar.gz -rwxrwxrwx. 1 root root 607698 Jul 1 2019 zlib-1.2.11.tar.gz [root@192 nginxOfflinePack]# tar -zxvf openssl-1.0.2r.tar.gz openssl-1.0.2r/ACKNOWLEDGMENTS [root@192 nginxOfflinePack]# cd openssl-1.0.2r/ [root@192 openssl-1.0.2r]# ./config Operating system: x86_64-whatever-linux2 Configuring for linux-x86_64 Configuring for linux-x86_64 |
#此命令执行,耗时较长,大概5分钟
[root@192 openssl-1.0.2r]# make RY_PATH ${LDCMD} ${LDFLAGS} -o ${APPNAME:=sslv2conftest} sslv2conftest.o ${LIBDEPS} ) make[2]: Leaving directory `/root/export/servers/nginxOfflinePack/openssl-1.0.2r/test' gcc -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -c -o dtlstest.o dtlstest.c gcc -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -c -o ssltestlib.o ssltestlib.c |
#此命令也执行比较慢,大约执行2分钟
[root@192 openssl-1.0.2r]# make install make[1]: Leaving directory `/root/export/servers/nginxOfflinePack/openssl-1.0.2r/crypto' making install in ssl... make[1]: Entering directory `/root/export/servers/nginxOfflinePack/openssl-1.0.2r/ssl' make[1]: Leaving directory `/root/export/servers/nginxOfflinePack/openssl-1.0.2r/ssl' making install in engines... |
2.6 离线安装zlib
再次退到 nginxOfflinePack 这一层目录
[root@192 openssl-1.0.2r]# cd .. [root@192 nginxOfflinePack]# tar -zxvf zlib-1.2.11.tar.gz zlib-1.2.11/ zlib-1.2.11/adler32.c zlib-1.2.11/amiga/ zlib-1.2.11/ChangeLog zlib-1.2.11/CMakeLists.txt zlib-1.2.11/compress.c zlib-1.2.11/configure zlib-1.2.11/contrib/ zlib-1.2.11/crc32.c zlib-1.2.11/crc32.h zlib-1.2.11/deflate.c [root@192 nginxOfflinePack]# cd zlib-1.2.11/ [root@192 zlib-1.2.11]# root@192 zlib-1.2.11]# ./configure Checking for gcc... Checking for shared library support... Building shared library libz.so.1.2.11 with gcc [root@192 zlib-1.2.11]# make install rm -f /usr/local/lib/libz.a cp libz.a /usr/local/lib chmod 644 /usr/local/lib/libz.a cp libz.so.1.2.11 /usr/local/lib chmod 755 /usr/local/lib/libz.so.1.2.11 rm -f /usr/local/share/man/man3/zlib.3 cp zlib.3 /usr/local/share/man/man3 chmod 644 /usr/local/share/man/man3/zlib.3 rm -f /usr/local/lib/pkgconfig/zlib.pc cp zlib.pc /usr/local/lib/pkgconfig chmod 644 /usr/local/lib/pkgconfig/zlib.pc rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h cp zlib.h zconf.h /usr/local/include chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h [root@192 zlib-1.2.11]# |
2.7 安装nginx
经过前面几步骤,重要到了nginx的安装环节了。
再次退到 nginxOfflinePack 这一层目录
[root@192 nginxOfflinePack]# tar -zxvf nginx-1.16.0.tar.gz [root@192 nginxOfflinePack]# cd nginx-1.16.0/ [root@192 nginx-1.16.0]# ./configure checking for OS + Linux 3.10.0-862.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler |
#此命令大约执行1分钟
[root@192 nginx-1.16.0]# make objs/src/http/modules/ngx_http_split_clients_module.o \ objs/src/http/modules/ngx_http_referer_module.o \ objs/src/http/modules/ngx_http_rewrite_module.o \ objs/src/http/modules/ngx_http_proxy_module.o \ objs/src/http/modules/ngx_http_fastcgi_module.o \ objs/src/http/modules/ngx_http_uwsgi_module.o \ objs/src/http/modules/ngx_http_scgi_module.o \ objs/src/http/modules/ngx_http_memcached_module.o \ objs/src/http/modules/ngx_http_empty_gif_module.o \ [root@192 nginx-1.16.0]# make install make -f objs/Makefile install make[1]: Entering directory `/root/export/servers/nginxOfflinePack/nginx-1.16.0' test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx' |
2.8 安装启动nginx进行访问验证
cd /usr/local/nginx/sbin 执行启动命令:./nginx 执行停止指令./nginx -s stop |
2.9 nginx的验证
2.9.1 第1种验证方式
http://localhost:80
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 安装并运行成功。
2.9.2 第2种验证方式
#第二种方式: [root@192 sbin]# curl http://127.0.0.1:80 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> |
2.10 防火墙中开放nginx的端口
[root@192 sbin]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@192 sbin]# firewall-cmd --query-port=80/tcp no [root@192 sbin]# firewall-cmd --add-port=80/tcp --permanent success [root@192 sbin]# systemctl restart firewalld [root@192 sbin]# firewall-cmd --query-port=80/tcp yes [root@192 sbin]# firewall-cmd --list-ports 3306/tcp 80/tcp [root@192 sbin]# |
#远程服务器进行访问:http://192.168.1.126:80
Centos7系统离线安装nginx步骤(亲测,超详细步骤)_qq445829096的博客-CSDN博客_centos离线安装nginx
三 安装多个nginx
在linux下安装nginx的时候,一般在./configure的阶段会要求通过prefix设置安装路径。因此,在./configure的时候指定不同的prefix就可以安装多个nginx啦。
值得注意的是,安装完之后,两个nginx的监听端口要设置成不同的监听端口。否则,会有一个nginx无法启动。
3.1.在/root/export/servers/nginxOfflinePack目录 下执行
tar -zxvf nginx-1.16.0.tar.gz
3.2 首先创建一个work用户
useradd work
3.3.第一个nginx的安装配置
进入到nginx的安装目录:cd nginx-1.16.0
./configure --prefix=/home/work/nginx1
执行完后,再执行如下命令:
make && make install
3.4.第2个nginx的安装配置
进入到nginx的安装目录:cd nginx-1.16.0
./configure --prefix=/home/work/nginx2
执行完后,再执行如下命令:
make && make install
3.5.修改第一个nginx的监听端口
cd /home/work/nginx1/confvi nginx.conf
#修改启动用户为root
#修改端口:
server { 2. listen 8089; 3. server_name localhost; 4. index index.php index.html; 5. root /data/www/;6. }
3.6.启动第一个nginx
cd /home/work/nginx1/sbin
./nginx
访问页面:http://localhost:8089
3.7 修改第二个nginx配置
cd /home/work/nginx2/confvi nginx.conf
#修改启动用户为root
#修改端口:
server { 2. listen 8086; 3. server_name localhost; 4. index index.php index.html; 5. root /data/www/;6. }
3.8.启动第二个nginx
cd /home/work/nginx2/sbin
./nginx
访问页面:http://localhost:8086
参考:https://www.jb51.net/article/99087.htm
这篇关于linux同一台机器安装两台nginx的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!