Centos x64 6.2配置JSP环境
1、最小化安装服务器
2、yum 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-devel libidn libidn-devel openssl openssl-devel lsof
3、(1)下载完成jdk-7u17-linux-x64.tar.gz
(2)解压tar zxvf jdk-7u17-linux-x64.tar.gz
(3)解压后将其移动到mv jdk-7u17-linux-x64 /usr/local/jdk
(4)配置 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
4、解压apache-tomcat-7.0.37.tar.gz
]# mv apache-tomcat-7.0.37 /usr/local/tomcat
将tomcat相关配置复制到网站目录中去
]# mkdir -p /webdata/htdocs/www/shop/ROOT
]# cp -Rf /usr/local/tomcat/webapps /webdata/htdocs/www (备注:此部暂不用操作)
编辑tomcat的server.xml
Vi /usr/local/tomcat/conf/server.xml
<Host name="localhost" appBase="/webdata/htdocs/www/shop/ROOT"
unpackWARs="true" autoDeploy="true">
(目录中必须有ROOT,否则tomcat找不到)
启动tomcat /usr/local/tomcat/bin/startup.sh
使用lsof –i :8080
测试服务是否启动
[root@localhost bin]# lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 3065 root 40u IPv6 36361 0t0 TCP *:webcache (LISTEN)
5、安装pcre,,通过 yum install pcre pcre-devel
6、安装nginx
[root@localhost bin]# useradd www
[root@localhost bin]# mkdir -p /webdata/logs #日志目录
mkdir -p /webdata/htdocs/www/shop/ROOT #网页目录
[root@localhost bin]# chown -R www:www /webdata
开始配置nginx源码文件
[root@localhost nginx-1.2.7]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
出错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
需要安装pcre
下载新版pcre-8.32.tar.gz 解压安装
./configure
Make
Make install
继续nginx
[root@localhost nginx-1.2.7]# ./configure --user=www --group=www --prefix=/usr/l
ocal/nginx --with-http_stub_status_module --with-http_ssl_module
-------------------------------------------------------------------------------------------
安装Nginx时报错
安装pcre-devel解决问题
yum -y install pcre-devel
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解决办法:
yum -y install openssl openssl-devel
总结:
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install
7、配置nginx.conf 在/usr/local/tomcat/conf/nginx.conf
配置内容如下:
user www www;
worker_processes 1;
error_log /webdata/logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
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;
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;
#access_log logs/host.access.log main;
log_format wwwlog '$remote_addr -$remote_user[$time_local]"$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for';
access_log /webdata/logs/web.log wwwlog;
server {
listen 80;
server_name localhost;
index index.html index.htm index.jsp index.do;
root /webdata/htdocs/www/shop/ROOT;
if ( -d $request_filename)
{
# rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ .*\.(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8080; #תÏòtomcat´¦Àí
}
#charset koi8-r;
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
8、启动nginx
/usr/local/nginx/sbin/nginx
查看nginx
#ps –ef | grep nginx
这时,输入以下命令查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
或者无需这么麻烦,找到Nginx的Pid文件:
平滑重启:
kill -HUP `cat /usr/local/nginx/nginx.pid`
或者lsof –i:80
9、停止nginx的命令
#/usr/local/nginx/sbin/nginx -s stop
本文转自 lcpljc 51CTO博客,原文链接:http://blog.51cto.com/lcpljc/1170928,如需转载请自行联系原作者