Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the server side environment of Nginx+Tomcat

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge about how to configure the server-side environment of Nginx+Tomcat. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

1. Java jdk installation:

# download the corresponding jdk package, and then decompress and install it. Here the package name is: jdk-7u25-linux-x64.tar.gz

Tar-xzf jdk-7u25-linux-x64.tar.gz; mkdir-p / usr/java/; mv jdk1.7.0_25/ / usr/java/.

# then configure the environment variable so that jdk can be referenced anywhere, as follows:

# vi / etc/profile adds the following statement at the end:

Export java_home=/usr/java/jdk1.7.0_25 export classpath=$classpath:$java_home/lib:$java_home/jre/lib export path=$java_home/bin:$java_home/jre/bin:$path:$homr/bin

# source / etc/profile # make the environment variable take effect immediately

# java-- version # check the java version and see the jdk1.7.0_25 version means that java jdk is installed successfully.

2. Nginx installation:

Wget http://nginx.org/download/nginx-1.2.6.tar.gz useradd www tar zxvf nginx-1.2.6.tar.gz cd nginx-1.2.6/. / configure-user=www-group=www-prefix=/usr/local/nginx\-with-http_stub_status_module-with-http_ssl_module make & & make install

# nginx is installed, and then use the command: / usr/local/nginx/sbin/nginx-t to test ok, which means that nginx is installed successfully.

/ usr/local/nginx/sbin/nginx enter to start nginx, and you can see the nginx default page by visiting http://ip/.

3. Tomcat installation:

# download tomcat 6.0.30 or other versions from the official website:

Cd / usr/src & & tar xzf apache-tomcat-6.0.30.tar.gz

# you can use it by decompressing it directly. After decompressing, you can execute it, and copy two tomcat, named tomcat1 tomcat2.

Mv apache-tomcat-6.0.30 / usr/local/tomcat1 cp / usr/local/tomcat1 / usr/local/tomcat2-r

# modify tomcat1 and tomcat2 ports respectively. There are three ports that need to be modified, as follows:

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)

# Note * if the three ports of tomcat1 are 8005 8009 8080 respectively, then the tomcat2 ports are all + 1 on this basis, that is, 8006 8010 8081

# on a server, the port cannot be duplicated, otherwise an error will be reported.

# after modifying the port, start the two tomcat with the following startup command:

# how to prompt that the file is not available or the permissions are insufficient, and the bin directory of tomcat is required to grant execution permission to the sh file: chmod ostatx * .sh

/ usr/local/tomcat1/bin/startup.sh / usr/local/tomcat2/bin/startup.sh

# after startup, you can see 6 ports using netstat-tnl, which means that tomcat1 tomcat2 starts successfully. You can use http://ip:8080 http://ip:8081 to access the tomcat default page.

# if you need to modify the directory defined by the tomcat publishing directory, you need to make the following adjustments to create two publishing directories:

Mkdir-p / usr/webapps/ {www1,www2}

Edit vi / usr/local/tomcat1/conf/server.xml to add the following on the last line:

Edit vi / usr/local/tomcat2/conf/server.xml to add the following on the last line:

Tomcat1 publishes the contents of the directory:

Tomcat_1 jsp test page

Tomcat2 publishes the contents of the directory:

Tomcat_2 jsp test page

Then visit http://ip:8080, 8081 to view the test content.

4. Nginx+tomcat integration:

The integration is mainly to modify the nginx.conf configuration to give a complete online configuration of nginx.conf.Some parameters can be modified according to the actual needs:

User www www; 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/plain application/x-javascript text/css application/xml; gzip_vary on; # # 2012-12-19 change nginx logs 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'; upstream web_app {server 127.0.0.1 time_local 8080 weight=1 max_fails=2 fail_timeout=30s Server 127.0.0.1 chinaapp.sinaapp.com server 8081 weight=1 max_fails=2 fail_timeout=30s;} # chinaapp.sinaapp.com server {listen 80; server_name chinaapp.sinaapp.com; index index.jsp index.html index.htm; # release directory / data/www root / data/www; 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;}

# Note * the web_app defined by proxy_pass in the server segment must be the same as the web_app defined in upstream, otherwise the server cannot find the balance.

# as configured above, nginx+tomcat reverse proxy load balancer has been configured. If you want to do static and dynamic separation, you only need to add the following configuration to nginx to ok.

# configure nginx for static and dynamic separation

Location ~. *\. (html | htm | gif | jpg | jpeg | bmp | png | ico | txt | css) ${root / data/www; # expires defines the caching time of the user's browser as 3 days. If the static page is not updated frequently, it can be set to longer, which can save bandwidth and relieve the pressure on the server expires 3D;}

5. Enable the monitoring of nginx

1), nginx simple status monitoring

Add the following code to nginx.conf to monitor the current status of nginx, and then visit http://serverip/status to access

Location / status {stub_status on;access_log off;}

Generally displayed as

Active connections: 16 server accepts handled requests191226 191226 305915 reading: 0 writing: 1 waiting: 15

Ctive connections: the number of active connections initiated to the backend.

Server accepts handled requests: nginx handled a total of 24 connections, successfully created 24 handshakes (proving that there was no failure in the middle), and processed a total of 129 requests.

Reading: the number of header messages read by nginx to the client.

Writing: the number of header messages returned by nginx to the client.

Waiting: when keep-alive is enabled, this value is equal to active-(reading + writing), which means that nginx has been processed and is waiting for the resident connection of the next request instruction.

Note that this module is not compiled into nginx by default. If you want to use this module, specify it when you compile and install nginx:

. / configure-with-http_stub_status_module

Check to see if the installed nginx contains stub_status modules

# / usr/local/nginx/sbin/nginx-vtls sni support disabledconfigure arguments:-prefix=/usr/local/nginx-- user=www-- group=www-- with-http_stub_status_module-- with-file-aio-- with-http_ssl_module

2). Graphical monitoring of nginx-nginx-rrd stats

Nginx-rrd is an official nginx monitoring tool recommended by nginx. Using nginx-rrd, you can easily generate charts and make it easy for us to view.

A. Running environment (centos):

You need to install the drawing tool rrdtool and the corresponding perl module before installation. You can run it first:

Yum install rrdtool libhtml-parser-perl libwww-perl librrds-perl librrd2-dev

Make sure that rrdtool and the corresponding perl are installed.

B. Installation configuration

Download:

Wget http://soft.vpser.net/status/nginx-rrd/nginx-rrd-0.1.4.tgz

Decompress:

Tar zxvf nginx-rrd-0.1.4.tgz

Enter the nginx-rrd directory

Cd nginx-rrd-0.1.4/

Copy the main program:

Cp usr/sbin/* / usr/sbin

Copy Profil

Cp etc/nginx-rrd.conf / etc

Copy timing execution files:

Cp etc/cron.d/nginx-rrd.cron / etc/cron.d

Create the nginx-rrd build directory:

Mkdir / home/wwwroot/nginx & & mkdir / home/wwwroot/nginx/rrdcp html/index.php / home/wwwroot/nginx

Edit / home/wwwroot/nginx/index.php change login password

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report