• Linux-Nginx+Tomcat


    系统版本:centos7

    本案例是在单台服务器上安装配置。

    1.源码包安装Nginx

    #安装依赖包
    yum -y install wget gcc make pcre-devel zlib-devel tar zlib openssl-devel
    
    #下载nginx源码包
    wget https://nginx.org/download/nginx-1.17.9.tar.gz 
    
    #解压进入目录
    tar nginx-1.17.9.tar.gz
    cd ./nginx-1.17.9
    
    #添加nginx用户
    useradd nginx -s /sbin/nologin
    
    #编译安装(参数可根据自己需求进行添加)
    ./configure --prefix=/usr/local/nginx --user=nginx 
    --group=nginx --with-http_ssl_module 
    --with-http_stub_status_module 
    --with-stream=dynamic
    
    make && make install
    
    #创建软链接
    ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
    
    #启动nginx
    nginx
    
    #测试nginx
    浏览器输入:http://服务器ip
    

     2.源码安装Tomcat

    #2.1安装部署jdk环境
    #下载jdk8(运行java程序使用)
    https://download.oracle.com/otn/java/jdk/8u231-b11/5b13a193868b4bf28bcb45c792fce896/jdk-8u231-linux-x64.tar.gz
    
    #下载maven(构建jdk的war包使用)
    https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
    
    #解压jdk和maven到指定路径
    tar -zxvf jdk-8u231-linux-x64.tar.gz -C /usr/local/
    tar -zxvf apache-maven-3.5.0-bin.tar.gz -C /usr/local/
    
    #重命名JDK和mven
    mv /usr/local/jdk1.8.0_231/ /usr/local/jdk1.8
    mv /usr/local/apache-maven-3.5.0/ /usr/local/maven3.5
    
    #添加环境变量
    cat >> /etc/profile <<'EOF'
    JAVA_HOME=/usr/local/jdk1.8
    MAVEN_HOME=/usr/local/maven3.5
    PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
    export JAVA_HOME MAVEN_HOME PATH
    EOF
    
    #加载profile文件
    source /etc/profile
    
    #测试jdk
    java -version
    
    #显示此信息表示安装成功
    java version "1.8.0_231"
    
    
    #2.2安装部署tomcat8
    #下载tomcat8.5(支持jdk7及以上版本)
    https://tomcat.apache.org/download-80.cgi
    
    #解压到指定目录
    tar -zxvf apache-tomcat-8.5.55.tar.gz -C /usr/local/
    
    #重命名tomcat(直接解压就可用)
    mv /usr/local/apache-tomcat-8.5.55/ /usr/local/tomcat-8.5
    
    #启动tomcat
    /usr/local/tomcat-8.5/bin/startup.sh
    
    #测试tomcat
    在浏览器输入http://服务器ip:8080
    

     3.Nginx反向代理配置

    #3.1Nginx主配置文件配置
    vim /usr/local/nginx/conf/nginx.conf
    
    user nginx;    #运行用户
    worker_processes auto;     #进程数
    error_log /usr/local/nginx/logs/error.log;
    pid logs/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/local/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;     #最大连接数(可根据服务器性能相应调大)
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"';
    
        access_log  /usr/local/nginx/logs/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             mime.types;
        default_type        application/octet-stream;
    
        include /usr/local/nginx/conf/conf.d/*.conf;     #虚拟主机配置文件目录
    
    }
    #3.2虚拟主机文件配置
    vim /usr/local/nginx/conf/conf.d/solo.soulmate.com.conf 
    
    upstream static.solo {
       server 127.0.0.1:80;    #静态资源访问
    }
    
    upstream dynamic.solo {
       server 127.0.0.1:8080;    #动态资源访问
    }
    
    server {
        listen 80;
        server_name solo.soulmate.com;    #域名解析(根据自己需求填写域名)
        access_log logs/solo.access.log main;
    
        location / {
            proxy_pass http://dynamic.solo$request_uri;
            proxy_set_header  Host $host:$server_port;
            proxy_set_header  X-Real-IP  $remote_addr;
            client_max_body_size  10m;
    
        }
    
        location ~ .(html|css|js|jpg|png|gif|svg|ico)$ {
            proxy_pass http://static.solo;
        }
    }
    

     到此单机配置完成,如果需要集群配置,则只需修改IP地址配置即可。

  • 相关阅读:
    数据库性能优化摘录
    关于海量用户访问的通用技术架构的一些思考
    Rose建模示例
    ASP.NET2.0下实现分布式StateServer(状态服务器)
    Apache + Tomcat 实现简单集群
    StateServer 解决 Session过期和分布式保存Session
    ASP.NET动态修改浏览器title,keywords,descrtptions,csslink,meta,icon等
    用户登录体验(自动时间锁)
    百度ueditor一些使用技巧
    C# AJAX中弹出提示窗口
  • 原文地址:https://www.cnblogs.com/qiandong/p/12879085.html
Copyright © 2020-2023  润新知