1. 程式人生 > >nginx+tomcat釋出web程式

nginx+tomcat釋出web程式

參考博文https://www.cnblogs.com/tuojunjie/p/6229783.html

1、因為nginx已經按照,跳過安裝,linux是租的阿里伺服器

2、檔案準備,通過flashFXP或者其他軟體上傳war包到指定目錄

3、安裝tomcat

cp -r apache-tomcat-8.5.23.tar.gz /mnt/upload/ryqp/

rm -rf apache-tomcat-8.5.23

tar xzf apache-tomcat-8.5.23.tar.gz 
4、用nginx代理
#ryqp服務
    upstream ryqp_server{
        server localhost:8089;
    }


     #ryqp 虛擬站點
     server {
        listen       80;
        server_name  test.ryqp.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           # root   html;
           # index  index.html index.htm;
           #proxy_pass http://sdk_server/muzhike/;
           #rewrite ^/muzhike/(.*)$ /$1 last;
           proxy_pass http://ryqp_server/ryqp/;
           rewrite ^/ryqp/(.*)$ /$1 last;
           proxy_set_header        X-Real-IP       $remote_addr;
           proxy_set_header        Host            $host;
           proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_pass_request_headers              on;

        }

        #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        #   proxy_pass http://ryqp_server/ryqp;
        #}

        #location ~ .*\.(js|css)?$ {
        #    proxy_pass http://ryqp_server/ryqp;
        #}

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
配置的有點簡單,見諒吶,可以參考其他大神的作品

重啟nginx:在sbin目錄下

[[email protected] conf]# cd ../sbin/
[[email protected] sbin]# ./nginx -s reload

啟動好後,進行驗證

5、配置tomcat:service.xml

<Connector port="8089" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
如果是一個web,預設8080就可以了,我這邊已經被佔用了
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
	<Context path="/ryqp" docBase="/mnt/upload/ryqp/ha-ryqp-interface-1.0.0-SNAPSHOT.war" reloadable="true"></Context>
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- 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 "%r" %s %b" />

      </Host>

新增context標籤,指定war包路徑,這樣就沒必要放到webapps下面了

到tomcat的bin目錄下使用指令碼命令  ./startup.sh

可以檢視log日誌,檢視啟動

 訪問web專案路徑即可驗證