centos-64整合nginx和tomcat
1、安裝wget和依賴包
yum install wget
yum install make gcc gcc-c++ autoconf automake
yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel
2、創建nginx目錄并下載nginx最新穩定版本
mkdir /home/nginx/
wget nginx.org/download/nginx-1.2.8.tar.gz
3、解壓并查看nginx的配置幫助
tar xvzf nginx-1.2.8.tar.gz
cd /home/nginx/nginx-1.2.8
[root@nignx nginx-1.2.8]# ./configure --help
4、配置nginx的安裝選項
./configure
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
Configuration summary
? + using system PCRE library
? + OpenSSL library is not used
? + md5: using system crypto library
? + sha1: using system crypto library
? + using system zlib library
? nginx path prefix: "/usr/local/nginx"
? nginx binary file: "/usr/local/nginx/sbin/nginx"
? nginx configuration prefix: "/usr/local/nginx/conf"
? nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
? nginx pid file: "/usr/local/nginx/logs/nginx.pid"
? nginx error log file: "/usr/local/nginx/logs/error.log"
? nginx http access log file: "/usr/local/nginx/logs/access.log"
? nginx http client request body temporary files: "client_body_temp"
? nginx http proxy temporary files: "proxy_temp"
? nginx http fastcgi temporary files: "fastcgi_temp"
? nginx http uwsgi temporary files: "uwsgi_temp"
? nginx http scgi temporary files: "scgi_temp"
5、安裝
make && make install
6、啟動、重啟、停止nginx(注意安裝目錄)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf//nginx.conf
/usr/local/nginx/sbin/nginx -s reload
pkill -9 nginx
7、關閉防火墻(或者添加80端口的規則)
service iptables stop
8、配置jdk和tomcat
wget http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
chmod +x jdk-6u45-linux-x64.bin
mv jdk1.6.0_45/ /usr/local/jdk
vi /etc/profile添加如下內容
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin"
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
source /etc/profile使得配置生效
wget http://mirror.esocc.com/apache/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.tar.gz
tar zxvf apache-tomcat-6.0.36.tar.gz
mv apache-tomcat-6.0.36 /usr/local/tomcat
cp -rf /usr/local/tomcat/webapps/* /home/www/
vi /usr/local/tomcat/conf/server.xml修改appBase="webapps"為appBase="/home/www/",即網頁根目錄
9、配置nginx.conf
vi /usr/local/nginx/conf/nginx/conf
[root@nignx conf]# cat nginx.conf
#user ?nobody;
worker_processes ?2;
#error_log ?logs/error.log;
#error_log ?logs/error.log ?notice;
#error_log ?logs/error.log ?error;
#pid ? ? ? ?logs/nginx.pid;
events {
? ? use epoll;
? ? worker_connections ?1024;
}
http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;
? ? #log_format ?main ?'$remote_addr - $remote_user [$time_local] "$request" '
? ? # ? ? ? ? ? ? ? ? ?'$status $body_bytes_sent "$http_referer" '
? ? # ? ? ? ? ? ? ? ? ?'"$http_user_agent" "$http_x_forwarded_for"';
? ? #access_log ?logs/access.log ?main;
? ? sendfile ? ? ? ?on;
? ? tcp_nopush ? ? on;
? ? keepalive_timeout ?65;
? ? gzip ?on;
? ? gzip_http_version 1.0;
? ? gzip_min_length 1000;
? ? gzip_buffers 4 32k;
? ? gzip_comp_level 5;
? ? gzip_disable "MSIE [1-6].";
? ? gzip_types text/plain application/x-javascript text/css text/javascript application;
? ? gzip_vary on;
? ? upstream tomcat_server {
? ? ? ? server 127.0.0.1:8080;
? ? }
? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;
? ? ? ? #charset koi8-r;
? ? ? ? #access_log ?logs/host.access.log ?main;
? ? ? ? root ? /home/www/webapps;
? ? ? ? location /manageUI/ {
? ? ? ? ? ? index /home/www/ROOT/test.jsp;
? ? ? ? ? ? proxy_pass http://tomcat_server;
? ? ? ? ? ? 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_set_header Via "nginx";
? ? ? ? }
? ? ? ? #error_page ?404 ? ? ? ? ? ? ?/404.html;
? ? ? ? # redirect server error pages to the static page /50x.html
? ? ? ? #
? ? ? ? error_page ? 500 502 503 504 ?/50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root ? html;
? ? ? ? }
? ? }
}
以上就完成了nginx和tomcat的整合
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
