Nginx反向代理

网友投稿 959 2022-11-06

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

Nginx反向代理

Nginx 服务器的反向代理服务是其最常用的重要功能,由反向代理服务也可以衍生出很多与此相关的 Nginx 服务器重要功能。

一、安装依赖包

yuminstall-y gccgcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

依赖包说明:

1、编译依赖 gcc 环境,所以需要:gcc gcc-c++;

2、PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库,所以需要:pcre pcre-devel ;

3、zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库,所以需要:zlib zlib-devel ;

4、OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库,所以需要:openssl openssl-devel ;

二、从官网下载安装包

wgethttps://nginx.org/download/nginx-1.16.0.tar.gz

三、解压并安装

tarzxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

./configure --prefix=/usr/local/nginx —user=www —group=www

make&&makeinstall

四、测试安装是否成功

[root@localhost ~]# nginx -V

nginx version: nginx/1.16.0

built bygcc4.8.520150623(Red Hat4.8.5-36) (GCC)

configure arguments:--prefix=/usr/local/nginx

五、启动nginx服务

cd usr/local/nginx/sbin

./nginx

六、验证服务是否启动成功

[root@localhost sbin]# netstat -ntlp |grepnginx

tcp       0     00.0.0.0:80             0.0.0.0:*               LISTEN     349/nginx: master

七、访问一下

[root@localhost sbin]# curl 172.17.1.151

Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.

For online documentation and support please refer to

nginx.org.

Commercial support is available at

nginx.com.

Thank you for using nginx.

八、下载tomcat

https://tomcat.apache.org/download-80.cgi

解压:

[root@localhost opt]# tar -vxf apache-tomcat-8.5.43.tar

改名:

[root@localhost opt]# mv apache-tomcat-8.5.43 usr/local/tomcat

[root@localhost opt]# cd usr/local/tomcat/

[root@localhost tomcat]# ls

bin          CONTRIBUTING.md  logs      RELEASE-NOTES  webapps

BUILDING.txt  lib              NOTICE     RUNNING.txt    work

conf          LICENSE          README.md  temp

九、配置java环境

[root@localhost tomcat]# yum install java-1.8.0* -y

[root@localhost tomcat]# java -version

openjdk version "1.8.0_212"

OpenJDK Runtime Environment (build 1.8.0_212-b04)

OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

十、启动查看tomcat

[root@localhost bin]# ./startup.sh

Using CATALINA_BASE:   /usr/local/tomcat

Using CATALINA_HOME:   /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME:        /usr

Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Tomcat started.

十一、tomcat是个java进程

[root@localhost bin]# netstat -tunlp|grep tomcat

[root@localhost bin]# netstat -tunlp|grep java

tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      17248/java

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      17248/java

tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      17248/java

http://172.17.1.151:8080

十二、反向代理:之前的注释掉

十三、重启nginx

[root@localhost nginx]# cd sbin/

[root@localhost sbin]# ls

nginx

[root@localhost sbin]# ./nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost sbin]# ./nginx -s reload

十四、访问80端口可以直接访问tomcat

http://172.17.1.151

上一篇:告警平台策略(告警平台 开源)
下一篇:软件测试培训之软件性能测试基础
相关文章

 发表评论

暂时没有评论,来抢沙发吧~