ubuntu10.04 安装nginx 及和tomcat的整合

来源:互联网 发布:m3轮毂数据 编辑:程序博客网 时间:2024/06/06 05:26

 1. 准备软件

apache-tomcat-6.0.26.tar.gz   http://tomcat.apache.org/download-60.cgi

jdk-6u20-linux-i586.bin           http://java.sun.com/javase/downloads/index.jsp

nginx-0.7.65.tar.gz                   http://nginx.org/en/download.html

pcre-8.02.tar.gz                        http://sourceforge.net/projects/pcre/files/

 

jdk tomcat 的安装过程略,假设以上软件都放在桌面。安装在/usr/local 这个目录里面。

 

 

cd ~/desktop

 

2.安装pcre.

tar xzvf  pcre-8.02.tar.gz

 

cd pcre-8.02

sudo mkdir /usr/local/pcre

./configure –prefix = /usr/local/pcre

make

sudo make install

 

3.安装 nginx.

cd ~/desktop

sudo mkdir /usr/local/nginx

tar xzvf    nginx-0.7.65.tar.gz

cd           nginx-0.7.65 

 

sudo ./configure --prefix=/usr/local/nginx --with-pcre=~/desktop/pcre-8.02  --with-http_stub_status_module --without-http-cache  --without-http_gzip_module

sudo make
sudo make install
 
4.配置nginx
cd /usr/local/nginx/conf
sudo cp nginx.conf   ngix.confbak
 
 sudo vim /usr/local/nginx/conf/nginx.conf.
 
改成我下面这个样子就可以了,注意哦,我的html 文档是放在/var/www/这个目录里面的,你自己的要视情况而定。
 
 
#user  nobody;
worker_processes  8;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    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  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /var/www/;
            index  index.html index.htm;
        }
        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;
           }
 
 
        #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;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ /.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ /.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ //.ht {
        #    deny  all;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}
 
验证配置文件是否正确:
# /usr/local/nginx/sbin/nginx –t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
出现这个提示说明没有问题。
 
 
6.启动 nginx
sudo  /usr/local/nginx/sbin/nginx
在浏览器输入 localhost 能访问的话,
就ok!!! 
 
nginx启动脚本 

sudo vim /etc/init.d/nginx
#!/bin/bashcase $1  instart)        /usr/local/nginx/sbin/nginx;;stop)        killall -9 nginx;;test)        #nginx -t -c /usr/local/nginx/conf/nginx.conf       /usr/local/nginx/sbin/nginx  -t;;restart)        ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP;;show)        ps -aux|grep nginx;;esac

sudo chmod 755 /etc/init.d/nginx

 

原创粉丝点击