Integrating Nginx and Tomcat

Source: Internet
Author: User
Tags nginx reverse proxy

<--Directory--

1, why to integrate Nginx + Tomcat Services

2. Installing Nginx

3. Installing the JDK

4. Install Tomcat

5, Nginx reverse proxy load Balancing configuration

6, Nginx static and dynamic separation configuration

7. Modify the Tomcat access path


"Why integrate Nginx + Tomcat Services"

1, early resin, Tomcat to httpd service support is not good

2, Tomcat, resin,rewrite function, Expires,gzip function support is not good

3, in order to match the static and dynamic separation


"Installation Nginx"

Yum-y Groupinstall "Development tools" "Development Library"

Yum-y install gcc gcc-c++ make pcre-devel OpenSSL openssl-devel

Useradd-m-s/sbin/nologin www

Cd/opt #源码包存文路径

TAR-ZXF nginx-1.8.0.tar.gz

CD nginx-1.8.0

./configure--prefix=/usr/local/nginx--pid-path=/usr/local/nginx/nginx.pid--user=www--group=www--with-http_ssl_ Module--with-http_flv_module--with-http_stub_status_module--with-http_gzip_static_module-- Http-client-body-temp-path=/usr/local/nginx/client--http-proxy-temp-path=/usr/local/nginx/proxy-- http-fastcgi-temp-path=/usr/local/nginx/fcgi--http-uwsgi-temp-path=/usr/local/nginx/uwsgi--http-scgi-temp-path =/usr/local/nginx/scgi--with-pcre--without-http_rewrite_module

Make

Make install

Rm-f/usr/local/nginx/conf/nginx.conf

cp/opt/nginx.conf/usr/local/nginx/conf/

Cp/opt/nginx/etc/init.d/nginx

ELinks--dump http://localhost


"Install JDK"

Cd/opt

RPM-IVH jdk-7u79-linux-x64.rpm

cd/usr/java/

MV jdk1.7.0_79//USR/LOCAL/JDK

Sed-i ' Export jre_home=/usr/local/jdk '/ETC/BASHRC

Sed-i ' Export Java_bin=/usr/local/jdk/bin '/ETC/BASHRC

Sed-i ' Export path= $JRE _home/bin: $PATH '/ETC/BASHRC

Sed-i ' Export classpath=.: $JRE _home/lib/dt.jar: $JRE _home/lib/tools.jar '/ETC/BASHRC

Sed-i ' export jre_home java_bin PATH CLASSPATH '/ETC/BASHRC

Source/etc/bashrc

Echo $JRE _home

Java-version


"Install Tomcat"

Cd/opt

Unzip Apache-tomcat-7.0.61-windows-x64.zip

MV Apache-tomcat-7.0.61/usr/local/tomcat

Cd/usr/local/tomcat/bin

chmod +x *.sh

./startup.sh

NETSTAT-TULNP | grep:8080

ELinks--dump http://localhost:8080


"Nginx Reverse proxy Load Balancer Configuration"

HTTP {

...

Upstream Webgrp {

Server 192.168.1.233:8080; #服务器组下的IP和端口号

Server 192.168.1.234:8080; #每台机轮询一次

}

...

server {#servier端跟upstream同级

Location/api {

Proxy_pass http://webgrp; #接收到443的请求后代替访问tomcat的8080端口


"Nginx Static and dynamic separation configuration"

server {

Listen 80;

server_name localhost; #如果这里做了域名解析, just fill in the domain name here.

root HTML; #开启nginx让其解析静态文件

Location ~. *\. (GIF|JPG|JPEG|PNG|BMP|IOC|SWF|RAZ|ZIP|TXT|FLV|MID|DOC|PPT|PDF|XLS|HTML|HTM|SHTML|MP3|WMA|JS|CSS) $ {# The static files listed are given to Nginx processing

Expires 7d; #7天过期

}


"Modify Tomcat Access Path"

Vim/usr/local/tomcat/conf/server.xml

...

<context path= "" docbase= "/usr/local/tomcat/webapps/" debug= "0" privileged= "true"/> #把Context path to the current line

...


Note: All Nginx and Tomcat will reboot to take effect after modifying the configuration file.


This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1791372

Integrating Nginx and Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.