一、安裝
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
執行下面命令使變更生效:
# source /etc/profile
啟動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; }}
新聞熱點
疑難解答