In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Nginx+Tomcat dynamic and static separation architecture
Nginx+tomcat is the current mainstream java web architecture, Nginx dynamic and static separation is simply to separate dynamic and static requests, can not be understood as simply the physical separation of dynamic pages and static pages. Strictly speaking, dynamic requests should be separated from static requests, which can be understood as using Nginx to deal with static pages, Tomcat and Resin to come out dynamic pages.
From the current implementation point of view, dynamic and static separation can be roughly divided into two types: one is simply to separate static files into separate domain names and put them on separate servers, which is also a popular solution at present; another method is to release dynamic and static files together and separate them through nginx.
Nginx server
1. Preparation of installation environment
Operating system version
Kernel version
Virtual machine IP address
CentOS 7.0
3.10.0-229.el7.x86_64
192.168.137.128
2. Install dependency package install gcc,gcc-c++,automake
Yum-y install gcc gcc-c++ automake
Install pcre,pcre-devel
To support the functionality of rewrite, you need to install pcre
Yum-y install pcre pcre-devel
Install openssl,openssl-devel
Support for ssl functionality
Yum-y install openssl openssl-devel
Install zlib, zlib-devel
Support for gzip compression
Yum-y install zlib zlib-devel
3. Source code compilation and installation
The official stable version of nginx-1.8.1 selected for this installation
1. Create nginx system users
[root@bogon ~] # useradd-r nginx
[root@bogon ~] # id nginx
Uid=997 (nginx) gid=995 (nginx) groups=995 (nginx)
[root@bogon local] # cd / usr/local/src/
[root@bogon src] # rz
[root@bogon src] # ls
Nginx-1.8.1.tar.gz
[root@bogon src] # tar-xzvf nginx-1.8.1.tar.gz
[root@bogon src] # cd nginx-1.8.1
[root@bogon nginx-1.8.1] # / configure-- prefix=/usr/local/nginx-- with-http_ssl_module-- with-http_stub_status_module
[root@bogon nginx-1.8.1] # make & & make install
After installation, start the service with / usr/local/nginx/sbin/nginx and then visit to see the test page.
JDK,tomcat installation (tomcat server)
Download the software by yourself
[root@bogon src] # tar-xf jdk-8u73-linux-x64+%281%29_.gz
[root@bogon src] # mv jdk1.8.0_73/ / usr/java/
[root@bogon src] # vi/etc/profile finally adds the following paragraph
ExportJAVA_HOME=/usr/java/jdk1.8.0_73
ExportCLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
ExportPATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
[root@bogon src] # source/etc/profile to make it effective
Test Java
Deploy Tomcat
[root@bogon src] # tar-xzvf apache-tomcat-7.0.63.tar.gz
[root@bogon src] # cp apache-tomcat-7.0.63 / usr/local/tomcat1-a
[root@bogon src] # cp apache-tomcat-7.0.63 / usr/local/tomcat2-a
The TOMCAT profile server.xml modifies the tomcat port respectively:
Shutdown port: 8005 is mainly responsible for starting and shutting down.
Ajp port: 8009 is mainly responsible for equalization through ajp (commonly used for apache and tomcat integration)
Http port: 8080 can be accessed directly through the web page (nginx+tomcata integration)
Tomcat1: default port
Tomcat2: 8006 8010 8081 respectively
[root@bogonsrc] # vi / usr/local/tomcat2/conf/server.xml
Start tomcat
[root@bogon src] # / usr/local/tomcat1/bin/startup.sh
[root@bogon src] # / usr/local/tomcat2/bin/startup.sh
Ps-ef | grep tomcat can view services and start them
Netstat-ntulp | grep java can view the port on which the service is started
Client access:
Http://192.168.137.128:8080/
Http://192.168.137.128:8081/
You can see the test page of tomcat
If you need to modify the directory defined for yourself by the tomcat publishing directory, you need to make the following adjustments to create two publishing directories:
Mkdir-p / data/webapps/ {www1,www2}
Edit vi/usr/local/tomcat1/conf/server.xml to add content to the last line before.
Edit vi/usr/local/tomcat2/conf/server.xml to add content to the last line before.
Tomcat1 publishes the contents of the directory: index.jsp
123456TOMCAT_1 JSP Test Page
Tomcat2 publishes the contents of the directory: index.jsp
123456TOMCAT_2 JSP Test Page then restarts the service through IP plus port access test, which can be accessed normally.
Nginx+tomcat integration: Nginx dynamic and static separation equalization configuration: nginx.conf file configuration on nginx server
Worker_processes 8
Pid / usr/local/nginx/nginx.pid
Worker_rlimit_nofile 102400
Events
{
Use epoll
Worker_connections 102400
}
Http
{
Include mime.types
Default_type application/octet-stream
Fastcgi_intercept_errors on
Charset utf-8
Server_names_hash_bucket_size 128
Client_header_buffer_size 4k
Large_client_header_buffers 4 32k
Client_max_body_size 300m
Sendfile on
Tcp_nopush on
Keepalive_timeout 60
Tcp_nodelay on
Client_body_buffer_size 512k
Proxy_connect_timeout 5
Proxy_read_timeout 60
Proxy_send_timeout 5
Proxy_buffer_size 16k
Proxy_buffers 4 64k
Proxy_busy_buffers_size 128k
Proxy_temp_file_write_size 128k
Gzip on
Gzip_min_length 1k
Gzip_buffers 4 16k
Gzip_http_version 1.1
Gzip_comp_level 2
Gzip_types text/plainapplication/x-javascript text/css application/xml
Gzip_vary on
Log_format main'$http_x_forwarded_for-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $request_time $remote_addr'
# Equalization module
Upstream web_app {
# prevent switching during access and login. I'll do a test here to comment him.
# ip_hash
Server 192.168.137.128:8080 weight=1max_fails=2 fail_timeout=30s
Server 192.168.137.128:8081 weight=1max_fails=2 fail_timeout=30s
}
Server {
Listen 80
Server_name localhostwww.lijq.com
Index index.jsp index.html index.htm
# Local release directory / data/www
Root / data/www
# all requests go from the root
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://web_app;
Expires 3d
}
# priority for request for separation of movement and movement
Location. *\. (php | jsp | cgi)? $
{
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://web_app;
}
Location ~. *\. (html | htm | gif | jpg | jpeg | bmp | png | ico | txt | js | css) $
{
Root / data/www
# request browser cache time for 3 days
Expires 3d
}
}
}
Test the nginx profile
[root@bogon ~] # / usr/local/nginx/sbin/nginx-t
Nginx: the configuration file/usr/local/nginx/conf/nginx.conf syntax is ok
Nginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful
Smooth restart
/ usr/local/nginx/sbin/nginx-s reload
The test can check the balance success through http://192.168.137.128/ access, and the static and dynamic separation test is also successful.
Be careful
Smooth restart error report, there are two solutions for your reference
[root@bogon conf] # / usr/local/nginx/sbin/nginx-s reload
Nginx: [error] invalid PID number "" in "/ usr/local/nginx/nginx.pid"
Solution one
Sudo nginx-c/usr/local/etc/nginx/nginx.conf
Sudo nginx-s reload
Solution two
[root@bogon ~] # vi/usr/local/nginx/conf/nginx.conf
Note pid, just save and restart.
Debug log path Nginx
[root@bogon] # tail-f / usr/local/nginx/logs/
Access.log error.log nginx.pid
Tomcat
[root@bogon] # tail-f / usr/local/tomcat1/logs/
Catalina.2017-06-15.log host-manager.2017-06-15.log localhost.2017-06-22.log manager.2017-06-15.log
Catalina.2017-06-22.log host-manager.2017-06-22.log localhost_access_log.2017-06-15.txt manager.2017-06-22.log
Catalina.out localhost.2017-06-15.log localhost_access_log.2017-06-22.txt
[root@bogon] # tail-f / usr/local/tomcat2/logs/
Catalina.2017-06-15.log host-manager.2017-06-15.log localhost.2017-06-22.log manager.2017-06-15.log
Catalina.2017-06-22.log host-manager.2017-06-22.log localhost_access_log.2017-06-15.txt manager.2017-06-22.log
Catalina.out localhost.2017-06-15.log localhost_access_log.2017-06-22.txt
Attachment: http://down.51cto.com/data/2366775
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.