本文共 3303 字,大约阅读时间需要 11 分钟。
NGINX: 192.168.10.10 TOMCAT: 192.168.10.11
[root@nginx ~]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
[root@nginx ~]# tar axvf nginx-1.12.1.tar.gz
[root@nginx ~]# useradd nginx -s /sbin/nologin -M
[root@nginx ~]# cd nginx-1.12.1
[root@nginx ~]# ./configure --help
[root@nginx ~]# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --prefix=/usr/local/nginx-1.12.1/
[root@nginx ~]# make && make install
[root@nginx ~]# ln -sv /usr/local/nginx-1.12.1 /usr/local/nginx
# 默认配置文件中添加红色行
[root@nginx ~]# cat /usr/local/nginx/conf/nginx.conf|egrep -v "#|^$"
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /usr/local/nginx/conf.d/*.conf;
}
# 创建相应目录并添加如下配置文件
[root@nginx ~]# cat /usr/local/nginx/conf.d/proxy.conf
server {
listen 80 ;
server_name 192.168.10.10; #供用户访问的ip或域名,多个用空格分开
location /world {
proxy_pass http://192.168.10.11:8080; #映射到的代理服务器,可是ip或域名
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /kazihuo {
proxy_pass http://192.168.10.11:8080/kazihuo;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /nginx_status {
stub_status on;
access_log off;
}
}
[root@nginx ~]# /usr/local/nginx/sbin/nginx
JAVA环境配置
[root@tomcat ~]# mkdir -pv /usr/java
[root@tomcat ~]# cd /usr/java
#官网下载jdk后解压安装
[root@tomcat ~]# tar -axvf jdk1.7.0_55tgz
#/etc/profile添加如下配置
[root@tomcat ~]# cat /etc/profile
JAVA_HOME=/usr/java/jdk1.7.0_55
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
[root@tomcat ~]# source /etc/profile
[root@tomcat ~]# java -version
[root@tomcat ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
[root@tomcat ~]# tar -axvf apache-tomcat-8.5.24.tar.gz
[root@tomcat ~]# mv apache-tomcat-8.5.24 /usr/local/
[root@tomcat ~]# ln -sv /usr/local/apache-tomcat-8.5.24 /usr/local/tomcat
# 添加测试工程页面
[root@tomcat ~]# mkdir -pv /usr/local/tomcat/webapps/kazihuo/{classed,lib}
[root@tomcat ~]# mkdir -pv /usr/local/tomcat/webapps/world/{classed,lib}
[root@tomcat ~]# cat /usr/local/tomcat/webapps/kazihuo/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>JSP test Page</title>
</head>
<body>
<%
out.println("I am kazihuo.");
%>
</body>
</html>
[root@tomcat ~]# cat /usr/local/tomcat/webapps/world/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>JSP test Page</title>
</head>
<body>
<%
out.println("Hello world !");
%>
</body>
</html>
[root@tomcat ~]# /usr/local/tomcat/bin/startup.sh
通过浏览器访问NGINX服务器地址,将实现反向代理到TOMCAT对应工程内容!
-------------------------------------------------------------
转载请保留此段声明,且在文章页面明显位置给出原文链接,谢谢!
------------------------------------------------------------------------------
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
------------------------------------------------------------------------------