Build Nginx+tomcat under Linux (ubuntu12.04)

Source: Internet
Author: User

First is the preparation of the installation package nginx7.9: Download nginx |tomcat7.0 Download Tomcat | JDK Download JDK7.0

The advantages of nginx too much, much better than Apache, more stable, more powerful, more and more developers choose to use Nginx to replace apache!!

Check this article http://blog.csdn.net/a454211787/article/details/22494485


First, after we have configured the JDK and downloaded the JDK, my default is download below and then extracted using the Linux command

$tar ZXVF JDK
After installation (I was installed in/usr/java), enter the Linux command

sudo gedit/etc/profile
Edit the profile file and add the following text

Export Java_home=/usr/java/jdk1.6.0_27export java_bin=/usr/java/jdk1.6.0_27/binexport PATH= $PATH: $JAVA _home/ Binexport classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jarexport java_home java_bin PATH CLASSPATH
Run
Java-version See if it's installed successfully
Then install Tomcat and rename it to Tomcat, edit/etc/frofile plus the following statement

  Catalina_home= "/usr/local/tomcat" Export Java_home catalina_home

Go to the Tomcat/bin directory and run
$./startup.sh
Then visit http://localhost:8080 to see if the access was successful. If you see Tomcat's welcome interface, congratulations on your half-success,


--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------

Next we install Nginx, we unzip the Nginx

$tar zxvf nginx~~~.tar.gz and $CD nginx/
$./configure
$make
$sudo make install (Remember to use super privilege here)
When executing the./configure will be thrownsaid the lack of Pcre library This is the HTTP Rewrite module, which is the URL static package

So first we're going to install this thing pcre download Pcre select version 7.9

$tar ZXVF Pcre~~.tar.gz$./configure$make$sudo make install

After installation, we are performing nginx installation lifemake, and then you can.

Next we execute the following command, create a proxy.conf file under Nginx's Conf folder, configure some proxy parameters

$CD/usr/local/nginx/conf$sudo Touch proxy.conf

#!nginx (-) # proxy.conf Proxy_redirect          off;proxy_set_header        Host $host;p roxy_set_header        X-real-ip $ REMOTE_ADDR;  #获取真实ip #proxy_set_header       x-forwarded-for   $proxy _add_x_forwarded_for; #获取代理者的真实ipclient_max_body_size    10m;client_body_buffer_size 128k;proxy_connect_timeout   90;proxy_send_timeout      90;proxy_read_timeout      90;proxy_buffer_size       4k;proxy_buffers           4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_ Size 64k;

Next, we want to edit the nginx.conf file

$sudo Gedit nginx.conf (remember if super privilege)
Write the basic configuration
#运行nginx所在的用户名和用户组 #user www www;  #启动进程数worker_processes 8; #全局错误日志及PID文件error_log/usr/local/nginx/logs/nginx_error.log crit;  Pid/usr/local/nginx/nginx.pid;  #Specifies the value for maximum file descriptors the can is opened by this process.  Worker_rlimit_nofile 65535; #工作模式及连接数上限events {use epoll; Worker_connections 65535;}  #设定http服务器, use its reverse proxy function to provide load balancing support http{#设定mime类型 include mime.types;  Default_type Application/octet-stream;  include/usr/local/nginx/conf/proxy.conf;  #charset gb2312;  #设定请求缓冲 server_names_hash_bucket_size 128;  Client_header_buffer_size 32k;  Large_client_header_buffers 4 32k;          Client_max_body_size 8m;  Sendfile on;    Tcp_nopush on;    Keepalive_timeout 60;  Tcp_nodelay on; # fastcgi_connect_timeout 300;# fastcgi_send_timeout 300;# fastcgi_read_timeout 300;# fastcgi_buffer_size 64k;# FASTC  Gi_buffers 4 64k;# fastcgi_busy_buffers_size 128k;# fastcgi_temp_file_write_size 128k; # gzip on;# gzip_min_length 1k;# GZIp_buffers 4 16k;# gzip_http_version 1.0;# gzip_comp_level 2;# gzip_types text/plain application/x-javascript    Text/css application/xml;# gzip_vary on; #limit_zone crawler $binary _remote_addr 10m;        # # #禁止通过ip访问站点 server{server_name _;        return 404;    } server {Listen 80;    server_name localhost;               Index index.html index.htm index.jsp, #设定访问的默认首页地址 root/home/www/web/root, #设定网站的资源存放路径 #limit_conn crawler 20;      Location ~. *.jsp$ #所有jsp的页面均交由tomcat处理 {index index.jsp; Proxy_pass http://localhost:8080; #转向tomcat处理} location ~. *\.    (gif|jpg|jpeg|png|bmp|swf) $ #设定访问静态文件直接读取不经过tomcat {expires 30d; } location ~. *\.    (JS|CSS)? $ {Expires 1h; } #定义访问日志的写入格式 log_format access ' $remote _addr-$remote _user [$time _local] "$request" "$status $body _bytes_sent "$http _referer" "$http _user_agent" $http _x_forwarded_for '; Access_log/usr/local/nginx/logs/localhost.log access; #设定访问日志的存放路径}}
Then we run the Linux command
#/usr/local/nginx/sbin/nginx-t

If the screen displays the following two lines of information, the configuration file is correct:  

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok   the configuration file /usr/local/nginx/conf/nginx.conf was tested successfull
But at this point, there's usually a problem.

Error while loading shared Libraries:libpcre.so.1:cannot open Shared object file:no such file or directory

Workaround:

Ln-s/usr/local/lib/libpcre.so.1/lib64

The 32-bit system:

Ln-s/usr/local/lib/libpcre.so.1/lib

Note:
/usr/local/lib/libpcre.so.1 file address after installation for Prce
Low version Prce corresponds to libpcre.so.1 for libpcre.so.0


And then
#/usr/local/nginx/sbin/nginx
#/usr/local/nginx/sbin/nginx-s stop
Check that nginx configuration is correct </span>
/usr/local/nginx/sbin/nginx-t
View Nginx Process
Ps-ef |grep Nginx

The simple Nginx+tomcat is set up, and the next thing to do is build NGINX+TOMCA clusters, and load balance

Load please indicate the source

http://blog.csdn.net/a837199685








Build Nginx+tomcat under Linux (ubuntu12.04)

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.