Linux下Nginx+Tomcat整合的安装与配置

1.安装及配置jdk1.8
 rpm -ivh jdk-8u171-linux-x64.rpm
vi /etc/profile
ln -s /usr/java/jdk1.8.0_171-amd64/ /usr/java/jdk1.8.0.171
配置Java环境变量
vi /etc/profile 最后一行添加一下内容
export JAVA_HOME="/usr/java/jdk1.8.0.171"
export JAVA_BIN=".:$PATH:$JAVA_HOME/bin"
export CLASSPATH="$JAVA_HOME/lib/:$JAVA_HOME/jre/lib/"
export CATALINA_HOME="/usr/local/tomcat"
source /etc/profile

[root@Mysql_Master html]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
至此,Java 安装完毕

2.安装tomcat
tar zxf apache-tomcat-8.5.31.tar.gz

mv apache-tomcat-8.5.31 /usr/local/tomcat
cd /usr/local/tomcat/

 cp -rf webapps/* /usr/local/nginx/html/bbs/
sed -i "s#appBase="webapps"#appBase="/usr/local/nginx/html/bbs/"#g"  /usr/local/tomcat/conf/server.xml
 /usr/local/tomcat/bin/startup.sh
 [root@Mysql_Master html]# netstat -tlunp|grep 8080
tcp        0      0 :::8080                     :::*                        LISTEN      27127/java
chown www.www bbs -R
tomcat 安装完成
 3.nginx整合tomcat
user www www;
worker_processes  8;

events {
    use epoll;
    worker_connections  65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    charset       utf-8;
    server_names_hash_bucket_size  128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 300m;
    tcp_nodelay on;
    client_body_buffer_size 512k;
    proxy_connect_timeout  5;
    proxy_read_timeout   60;
    proxy_send_timeout   5;
    proxy_buffer_size    16k;
    proxy_buffers       4 64k;
    proxy_busy_buffers_size  128k;
    proxy_temp_file_write_size 128k;
    gzip on;
    gzip_min_length    1k;
    gzip_buffers   4 16k;
    gzip_http_version  1.1;
    gzip_comp_level    2;
    gzip_types    text/plain application/x-javascript text/css application/xml;
    gzip_vary   on;
    upstream tomcat_server {
      server 127.0.0.1:8080;
    }
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  bbs.king.org;
        root         html/bbs;
        index        index.html index.htm index.jsp default.jsp index.do default.do;
        if (-d $request_filename)
        {
          rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
         }
         location ~ .*\.(jsp|jspx|do)?$ {
           proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_pass http://127.0.0.1:8080;
         }
         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
              expires  30d;
         }
         location ~ .*\.(js|css)?$ {
           expires 1h;
         }
         access_log off;
   }
    server {
        listen       80;
        server_name  blog.king.org;
        root         html/blog;
        index        index.html index.htm;
        }
    server {
        listen       80;
        server_name  status.king.org;
        stub_status  on;
        access_log   off;
        }
    }
/usr/local/nginx/sbin/nginx -t 语法检查

/usr/local/nginx/sbin/nginx 启动nginx
在浏览器中打开http://bbs.king.org/examples/jsp/ 测试是否成功


你可能感兴趣的:(web服务优化,Linux服务及故障排除)