Linux下安裝Nginx,并整合Tomcat,部署guns-admin

[toc]

Linux下安裝Nginx

  1. 下載nginx:http://nginx.org/en/download.html

    image.png
  1. 安裝依賴包

    yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
    
    // 安裝過程中,要選擇:y
    yum install GeoIP gd libXpm libxslt
    
    // 安裝gcc gcc-c++
    yum -y install gcc gcc-c++ autoconf automake make
    
  2. 安裝nginx

    // 解壓
    tar -zxvf nginx-1.14.0.tar.gz
    
    cd nginx-1.14.0/
    
    // 安裝到/usr/local/nginx目錄下
    ./configure --prefix=/usr/local/nginx
    
    make
    
    make install
    

nginx常用命令

  • 啟動命令:/usr/local/nginx/sbin/nginx
  • 重啟命令:/usr/local/nginx/sbin/nginx -s reload
  • 查看命令:ps -ef | grep nginx
  • 關(guān)閉命令:kill -9 進程號

nginx常用配置

配置文件位置:/usr/local/nginx/conf/nginx.conf

Nginx初試Tomcat,部署Guns-admin

網(wǎng)上關(guān)于nginx的資料很零碎,我就想整個tomcat+nginx運行一下guns的項目而已,訪問admin.idudiao.com后轉(zhuǎn)到服務(wù)器上的 http://localhost:8080/guns-admin上,無果,不是重定向次數(shù)過多,就是session失效。
最后,用了個折中的法子,訪問admin.idudiao.com后轉(zhuǎn)到服務(wù)器上的 http://localhost:8080

  1. 部署guns-admin項目,同時修改項目發(fā)布路徑為:''。 修改tomcat/conf/server.xml

    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
        
        <!--修改發(fā)布路徑-->
        <Context path="" docBase="/tomcat-8.0.53-guns/webapps/guns-admin"  debug="0" reloadable="true"/>
    
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
      </Host>
    
    

    參考:https://blog.csdn.net/u011042133/article/details/46349593

    • path是虛擬路徑;
    • docBase是應(yīng)用程序的物理路徑;
    • debug則是設(shè)定debug level, 0表示提供最少的信息,9表示提供最多的信息;
    • reloadable 如果為true,則tomcat會自動檢測應(yīng)用程序的/WEB-INF/lib 和/WEB-INF/classes目錄的變化,自動裝載新的應(yīng)用程序,可以在不重起
  2. 配置Nginx,修改/usr/local/nginx/conf/nginx.conf文件,在http{}模塊下添加:

    http {
        ...
        
        #add by dudiao at 20180815
        server {
            listen 80;
            server_name admin.idudiao.com;
            
            location / {
                proxy_pass http://localhost:8080;
                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 ~ .*\.(gif|jpg|jpeg|png|js|css)$ {
                root /tomcat-8.0.53-guns/webapps/guns-admin/;
                expires 1d;
            }
        }
        #add by dudiao end
        
        ...
    }
    
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容