centos7 搭建nginx和tomcat集成

一.安装jdk

1.yum install jdk

2.安装好了之后配置环境变量  在/etc/profile 

二.创建项目运行目录

 1. 我放在home目录  mkdir /web/webapps

三.安装tomcat

1.下载tomcat

2.解压后,修改conf里面server.xml  

<Host name="localhost" appBase="/home/web/webapps" deployOnStartup ="false"
unpackWARs="true" autoDeploy="true">

红色部分为修改 将appBase修改为项目放置路径 添加deployOnStartup ="false"

四.编译安装nginx

 1.下载nginx源码

 2. 解压源码  执行 ./configure --prefix=/usr/local/nginx 

       make & make install

五.修改nginx.conf

    在nginx /conf/nginx.conf   

     //分发地址tomcat

  upstream tomcat_testweb{
    server localhost:8080 weight=10;
  }

  server {
    listen 80;
    server_name 120.76.115.208;  //修改为服务器ip或域名
    root /home/web/webapps;        //修改为项目放置路径
    index index.jsp index.html index.htm;

    #charset koi8-r;

    #access_log logs/host.access.log main;
    location / {
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
    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_pass http://tomcat_testweb;        //使用分发地址
    expires 3d;
  }

 

    

 

posted @ 2016-04-05 20:19  散散客  阅读(441)  评论(0编辑  收藏  举报