一、安裝
1.安裝JDK
下載的jdk文件為:jdk-6u45-linux-x64.bin,執(zhí)行如下呼吁舉辦安裝:
#./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.設(shè)置情況變量:
編輯/etc下的profile文件,加上如下內(nèi)容:
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
執(zhí)行下面呼吁使改觀生效:
啟動tomcat并輸入http://domain:8080,假如看到貓的頁面即tomcat和jdk安裝樂成
新建文件目次/home/www為網(wǎng)站存放目次,配置server.xml文件,在Host name=”localhost”處將appBase=的指向路徑改為/home/www/web
建設(shè)index.jsp至/home/www/web/ROOT,內(nèi)容為:“hello!” 從頭啟動tomcat,從頭會見,假如看到index.jsp文件內(nèi)容hello!暗示配置樂成。
4.安裝Nginx
執(zhí)行如下呼吁解壓nginx:
# tar zxvf nginx-1.4.4.tar.gz
# mv nginx-1.4.4 nginx
同樣重定名了一下。
安裝nginx:
# ./configure --prefix=/opt/app/nginx
功效呈現(xiàn)了錯誤:error: C compiler cc is not found,按網(wǎng)上所說安裝編譯源碼所需的東西和庫:
#yum install gcc gcc-c++ ncurses-devel perl
再次安裝,發(fā)明尚有錯誤:the HTTP rewrite module requires the PCRE library.
執(zhí)行
# yum -y install pcre-devel openssl openssl-devel
終于樂成,
# ./configure --prefix=/opt/app/nginx
# make # make install
nginx安裝樂成后的安裝目次為/opt/app/nginx
二、Nginx方面的設(shè)置
在/usr/local/目次下別離安裝nginx和tomcat
為nginx添加conf.d目次,用于各項目標(biāo)設(shè)置,好比新建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權(quán)限,在http中添加 include /usr/local/nginx/conf.d/*.conf;
選擇一個項目如renhetoutiao, 目次/home/renhetoutiao/renhetoutiao/
三、Tomcat方面的設(shè)置
catalina.policy catalina.properties context.xml tomcat-users.xml server.xml web.xml
這5個設(shè)置文件就可以啟動一個tomcat實例,個中server.xml是必需設(shè)置的。
catalina.policy catalina.properties web.xml 可以利用默認(rèn)的,可以從安裝路徑copy,context.xml tomcat-users.xml可以不消。
所以每個項目我們只需要設(shè)置server.xml, 如renhetoutiao項目標(biāo)設(shè)置
<?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>