centos安装nginx+resin
一般网站使用java语言都是用tomcat,今天给大家介绍下用resin来支持java.Resin是CAUCHO公司的产品,是一个非常流行的application server,对servlet和JSP提供了良好的支持,性能也比较优良,resin自身采用JAVA语言开发!
系统:centos 5.5
需要的软件:resin-4.0.28.tar.gz nginx-1.2.0.tar.gz
1.安装前准备
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype \ freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel \ bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 \ krb5-devellibidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap \ openldap-clients openldap-servers libtool libtool-devel
下载java 1.6
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html
下载resin
wget http://www.caucho.com/download/resin-4.0.28.tar.gz
下载nginx
wget http://nginx.org/download/nginx-1.2.0.tar.gz
2.安装nginx
这个就不再介绍了,大家去看我这篇文章编译安装nginx并修改版本头信息.
3.安装java 1.6
这里就不讲解了,大家可以去看centos安装jdk 1.6这篇文章.
4.安装resin
tar zxf resin-4.0.28.tar.gz && cd resin-4.0.28
./configure --prefix=/usr/local/resin --with-java-home=/usr/java/default/
make && make install
/usr/local/resin/bin/resin.sh start
\cp init.d/resin /etc/init.d/resin
chmod +x /etc/init.d/resin
/sbin/chkconfig --add resin
/sbin/chkconfig resin on
ps aux|grep resin|grep -v grep
可以看到resin已经运行起了
5.整合nginx和resin
将resin默认目录修改成nginx网站目录相同
vi /usr/local/resin/conf/resin.xml
<!-- the default host, matching any host name --> <host id="" root-directory="."> <!-- - webapps can be overridden/extended in the resin.xml --> <web-app id="/" root-directory="webapps/ROOT"/>
改成
<!-- the default host, matching any host name --> <host id="" root-directory="."> <!-- - webapps can be overridden/extended in the resin.xml --> <web-app id="/" root-directory="/var/www/vhosts"/>
6.修改nginx配置文件
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vi /etc/nginx/nginx.conf
user nginx nginx; worker_processes 1; worker_rlimit_nofile 65535; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { use epoll; worker_connections 65535; } 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 /var/log/nginx/access.log main; server_names_hash_bucket_size 128; client_header_buffer_size 4k; large_client_header_buffers 4 32k; client_body_in_file_only clean; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; server_tokens off; client_body_buffer_size 512k; proxy_connect_timeout 5; proxy_send_timeout 60; proxy_read_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; # fastcgi_connect_timeout 300; # fastcgi_send_timeout 300; # fastcgi_read_timeout 300; # fastcgi_buffer_size 64k; # fastcgi_buffers 4 64k; # fastcgi_busy_buffers_size 128k; # fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.0; #gzip_disable "MSIE [1-5]\."; gzip_comp_level 4; gzip_types text/plain application/x-javascript text/css application/xml image/gif image/jpg image/jpeg image/png; #gzip_vary on; proxy_hide_header Vary; #limit_zone conlimit $binary_remote_addr 1m; #limit_conn conlimit 5; server { listen 80 default; server_name _; return 500; } server { listen 80; server_name blog.slogra.com; root /var/www/vhosts/; index index index.html index.htm index.jsp index.do; location ~ .*\.(jsp|jspx|do)?$ { 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://127.0.0.1:8080; } location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma){ expires 30d; } location ~ .*\.(js|css)?$ { expires 1d; } } }
7.测试
vi /var/www/vhosts/index.jsp
2 + 2 = <%= 2 + 2 %>
重启下resin和nginx
service resin restart
service nginx restart
访问https://blog.slogra.com,如下图
可以看到2+2=4,表示nginx和resin已经整合成功.
评论: