Nginx反向代理及配置实例

Nginx反向代理及配置实例

1.实现效果
(1)打开浏览器,在浏览器地址栏输入地址www.123.com,跳转Linux系统tomcat的主页面中;
2.准备工作:
(1)在Linux系统安装tomcat,使用默认端口8080

//安装的时候可以在官网下载下来的安装包放进linux系统中的usr包下的scr包中
//可以通过以下命令进行操作
//进入了tomcat所在的包
[root@fuhong-host-01 usr]# cd /usr/src
//查看该包下所有的文件,并看一下tomcat是否存在
[root@fuhong-host-01 src]# ls
//进行解压
[root@fuhong-host-01 src]# tar -xvf apache-tomcat-9.0.60.tar.gz
//启动tomcat,由于启动tomcat需要JDK环境,但我们可以使用它自带的JDK环境,查看JDK环境:
[root@fuhong-host-01 src]# java -version
//启动tomcat(这种方式可能会爆权限不够):
[root@fuhong-host-01 bin]# ./startup.sh
//当权限不够时,我们的操作可以采用以下形式:
[root@fuhong-host-01 bin]# cd/usr/src/apache-tomcat-9.0.60/bin
[root@fuhong-host-01 bin]# chmod u+x *.sh
[root@fuhong-host-01 bin]# ./startup.sh

//启动后,可以进入到日志文件中看一下启动的效果
//返回上一级目录
[root@fuhong-host-01 bin]# cd ..
[root@fuhong-host-01 apache-tomcat-9.0.60]# cd logs/
[root@fuhong-host-01 logs]# ls
[root@fuhong-host-01 logs]# tail -f catalina.out

(2)对外开放访问的端口
设置对外开放的规则:
firewall-cmd --add-port=8080/tcp --permanent
然后将防火墙重新加载(重启防火墙):
firewall-cmd --reload
查看开放的端口号:
firewall-cmd --list-all
打开防火墙:
通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。
再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。
如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。
(3)在windows系统上通过浏览器访问tomcat服务器

3.具体配置:
第一步:
在windows系统的host文件进行域名和ip对应关系的配置
位置:Nginx反向代理及配置实例_第1张图片
添加内容在hosts文件中,添加的内容为ip地址+域名
在这里插入图片描述
第二步:
在nginx进行请求转发的配置(反向代理配置)
我们可以在nginx.conf的配置文件中进行更改信息。
在server中将server_name的ip地址改成192.168.17.127;
在location中加入一个转发路径
proxy_pass http://127.0.0.1:8080;

你可能感兴趣的:(nginx,linux,tomcat)