首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx反向代理

Nginx反向代理

作者头像
胡齐
发布2019-09-23 18:54:54
6050
发布2019-09-23 18:54:54
举报
文章被收录于专栏:运维猫运维猫运维猫

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

<!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>

八、下载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

关于运维学习、分享、交流,笔者开通了微信公众号【运维猫】,感兴趣的朋友可以关注下,欢迎加入,建立属于我们自己的小圈子,一起学运维知识。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-07-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 运维猫 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档