一、安装
1.安装JDK
下载的jdk文件为:jdk-6u45-linux-x64.bin,执行如下呼吁举办安装:
#./jdk-6u12-linux-i586.bin
2.安装tomcat:
#tar zxvf apache-tomcat-6.0.18.tar.gz
#mv apache-tomcat-6.0.29 tomcat
这里我将解压后的apache-tomcat-6.0.29重定名为了tomcat利便操纵。
3.设置情况变量:
编辑/etc下的profile文件,加上如下内容:
JAVA_HOME="/opt/app/jdk1.6.0_45"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin"
CATALINA_HOME="/opt/app/tomcat"
export JAVA_HOME CATALINA_HOME
执行下面呼吁使改观生效:
启动tomcat并输入http://domain:8080,假如看到猫的页面即tomcat和jdk安装乐成
新建文件目次/home/www为网站存放目次,配置server.xml文件,在Host name=”localhost”处将appBase=的指向路径改为/home/www/web
建设index.jsp至/home/www/web/ROOT,内容为:“hello!” 从头启动tomcat,从头会见,假如看到index.jsp文件内容hello!暗示配置乐成。
4.安装Nginx
执行如下呼吁解压nginx:
# tar zxvf nginx-1.4.4.tar.gz
# mv nginx-1.4.4 nginx
同样重定名了一下。
安装nginx:
# ./configure --prefix=/opt/app/nginx
功效呈现了错误:error: C compiler cc is not found,按网上所说安装编译源码所需的东西和库:
#yum install gcc gcc-c++ ncurses-devel perl
再次安装,发明尚有错误:the HTTP rewrite module requires the PCRE library.
执行
# yum -y install pcre-devel openssl openssl-devel
终于乐成,
# ./configure --prefix=/opt/app/nginx
# make # make install
nginx安装乐成后的安装目次为/opt/app/nginx
二、Nginx方面的设置
在/usr/local/目次下别离安装nginx和tomcat
为nginx添加conf.d目次,用于各项目标设置,好比新建renhetoutiao.conf文件
server {
listen 80;
server_name devtoutiao.renhe.cn;
root /home/renhetoutiao/renhetoutiao/htdocs;
access_log /home/renhetoutiao/renhetoutiao/logs/access_log.log;
location = / {
rewrite ^/$ /index.shtml last;
}
location ~ .shtml {
proxy_pass http://localhost:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*.(js|css)?$ {
expires 1h;
}
}
server {
listen 80;
server_name devtoutiao.renhe.cn;
root /home/renhetoutiao/renhetoutiao/htdocs;
access_log /home/renhetoutiao/renhetoutiao/logs/access_log.log;
location = / {
rewrite ^/$ /index.shtml last;
}
location ~ .shtml {
proxy_pass http://localhost:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*.(js|css)?$ {
expires 1h;
}
}
对nginx的conf/nginx.conf修改,第二行 user root,赋予nginx root权限,在http中添加 include /usr/local/nginx/conf.d/*.conf;
选择一个项目如renhetoutiao, 目次/home/renhetoutiao/renhetoutiao/
三、Tomcat方面的设置
catalina.policy catalina.properties context.xml tomcat-users.xml server.xml web.xml
这5个设置文件就可以启动一个tomcat实例,个中server.xml是必需设置的。
catalina.policy catalina.properties web.xml 可以利用默认的,可以从安装路径copy,context.xml tomcat-users.xml可以不消。
所以每个项目我们只需要设置server.xml, 如renhetoutiao项目标设置
<?xml version='1.0' encoding='utf-8'?>
<Server port="8015" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/home/renhetoutiao/renhetoutiao/web" path="" />
</Host>
</Engine>
</Service>
</Server>
<?xml version='1.0' encoding='utf-8'?>
<Server port="8015" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/home/renhetoutiao/renhetoutiao/web" path="" />
</Host>
</Engine>
</Service>
</Server>