nginx+tomcat安装配置

# nginx+tomcat安装配置

#创建网站目录
mkdir -p /www/wwwroot
cd /www
#安装配置
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.14/bin/apache-tomcat-8.5.14.tar.gz
tar -zxvf apache-tomcat-8.5..tar.gz
mv apache-tomcat-8.5. tomcat
rm -rf ./tomcat/
rm ./tomcat/conf/tomcat-users.*
cp ./tomcat/conf/server.xml ./tomcat/conf/server.xml.$(date +%Y-%m-%d-%H%M%S).bak
vim ./tomcat/conf/server.xml
<Server port="" #关闭Tomcat指令8005,更改端口号
<Connector port="" #注释8009端口,与apache服务集成才需要
<Connector port="" protocol="HTTP/1.1" #web端口8080修改
<Host name="localhost" appBase="/www/wwwroot" #appBase="webapps" 路径修改
mkdir /www/wwwroot/ROOT
#web
mkdir -p /www/wwwroot2
mkdir /www/wwwroot2/ROOT
cp -a tomcat tomcat2
vim ./tomcat2/conf/server.xml
<Server port="" #关闭Tomcat指令8005,更改端口号
<Connector port="" protocol="HTTP/1.1" #web端口8080修改
<Host name="localhost" appBase="/www/wwwroot2" #appBase="webapps" 路径修改
#创建测试页
vim /www/wwwroot/ROOT/index.jsp
<%@ page language="java" %>
<html>
<head><title>ResinA</title></head>
<body>
<h1><font color="red">ResinA </font></h1>
<table align="centre" border="">
<tr>
<td>Session ID</td>
<% session.setAttribute("abc","abc"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
# 测试页2
vim /www/wwwroot2/ROOT/index.jsp #如上配置,ResinA改为ResinB
#启动
/www/tomcat/bin/startup.sh
/www/tomcat2/bin/startup.sh
# web 访问 ip:端口18080
#/usr/local/tomcat/bin/shutdown.sh
curl localhost: #nginx安装配置
#http://www.centoscn.com/nginx/2017/0119/8422.html
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y
/usr/sbin/nginx #启动
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak0
#vim /etc/nginx/nginx.conf
vim /etc/nginx/conf.d/.conf #添加测试host localhost:
#------------
upstream jsweb {
#ip_hash;
server localhost:;
server localhost:;
} server {
listen ;
server_name localhost;
#index index.jsp;
access_log logs/.log main;
error_log logs/.log notice; location / {
proxy_pass http://jsweb; #Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size ;
proxy_connect_timeout ;
proxy_send_timeout ;
proxy_read_timeout ;
proxy_buffer_size 4k;
proxy_buffers 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; ## set upload file size
client_max_body_size 20m;
}
#------------
mkdir /etc/nginx/logs
/usr/sbin/nginx -t #检测配置
/usr/sbin/nginx -s reload #重启nginx
/usr/sbin/nginx -s stop #关闭
#查看日志
tail -f -n /www/tomcat/logs/catalina.out
#修改tomcat获取真实ip
vim /www/tomcat/conf/server.xml
vim /www/tomcat2/conf/server.xml
pattern="%h %l %u %t &quot;%r&quot; %s %b" /> #改为如下
pattern="%{X-Real-IP}i %l %u %t &quot;%r&quot; %s %b" />
#增加
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="127\.0\.0\.1"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
trustedProxies="127\.0\.0\.1"/>
#重启tomcat
/www/tomcat/bin/shutdown.sh ; /www/tomcat/bin/startup.sh
/www/tomcat2/bin/shutdown.sh ; /www/tomcat2/bin/startup.sh
04-19 16:38