(https)nginx - tomcat(http)

实验拓扑

Nginx服务端进行配置

Nginx安装ssl模块

    [[email protected] nginx-1.8.0]# ./configure  --with-http_ssl_module  --with-pcre=/usr/local/src/pcre-8.37
    [[email protected] nginx-1.8.0]# make
    [[email protected] nginx-1.8.0]# make install
    [[email protected] nginx-1.8.0]# cd /usr/local/nginx/conf/

Openssl 加密

    [[email protected] conf]# openssl genrsa -des3 -out server.key 1024
    Generating RSA private key, 1024 bit long modulus
    ..................................++++++
    ..........................................................++++++
    e is 65537 (0x10001)
    Enter pass phrase for server.key:
    Verifying - Enter pass phrase for server.key:
    [[email protected] conf]# openssl req -new -key server.key -out server.csr
    Enter pass phrase for server.key:
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter ‘.‘, the field will be left blank.

    Country Name (2 letter code) [XX]:CN
    State or Province Name (full name) []:BEIJING
    Locality Name (eg, city) [Default City]:BEIJING
    Organization Name (eg, company) [Default Company Ltd]:GNNT
    Organizational Unit Name (eg, section) []:xuegod175.cn
    Common Name (eg, your name or your server‘s hostname) []:xuegod175.cn
    Email Address []:[email protected]

    Please enter the following ‘extra‘ attributes
    to be sent with your certificate request
    A challenge password []:123456
    An optional company name []:GNNT
    [[email protected] conf]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    Signature ok
    subject=/C=CN/ST=BEIJING/L=BEIJING/O=GNNT/OU=xuegod175.cn/CN=xuegod175.cn/[email protected]
    Getting Private key
    Enter pass phrase for server.key:

Nginx 服务器进行配置

    [[email protected] conf]# egrep -v  "#|^$" nginx.conf >nginx.conf.bak
    [[email protected] conf]# cp nginx.conf.bak  nginx.conf
    cp: overwrite `nginx.conf‘? yes
    [[email protected] conf]# cat nginx.conf
    user nginx nginx;
    worker_processes  1;
    events {
       worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
        listen         443 ssl;                                                  
        server_name    xuegod175.cn;#域名                          
        ssl_certificate      /usr/local/nginx/conf/server.crt;#证书路径      
        ssl_certificate_key   /usr/local/nginx/conf/server.key;#key路径              
  ssl_session_cache    shared:SSL:1m; #s储存SSL会话的缓存类型和大小                        
  ssl_session_timeout  5m; #会话过期时间                                               
  ssl_ciphers  HIGH:!aNULL:!MD5; #为建立安全连接,服务器所允许的密码格式列表                                          
  ssl_prefer_server_ciphers  on; #依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码
  location /     {                                                 
          root     html;                               
          index    index.html index.htm index.php;         
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
        }
    }
    [[email protected] conf]# /usr/local/nginx/sbin/nginx -s reload
    Enter PEM pass phrase:123456

通过浏览进行访问测试

安装tomcat

配置jdk

    Jdk的下载地址http://www.oracle.com/technetwork/java/javase/downloads/index.html       
    Tomcat的下载地址http://tomcat.apache.org/    
    [[email protected]~]# rpm -ivh jdk-8u60-linux-x64.rpm
    [[email protected]~]# vim /etc/profile                                                                 //修改变量
    export JAVA_HOME=/usr/java/jdk1.8.0_60/                     # JAVA_HOME变两个路径
    export JAVA_BIN=/usr/java/jdk1.8.0_60/bin
    export PATH=${JAVA_HOME}bin:$PATH                                 # 环境变量
    export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar   # 定义两个      类
    [[email protected]~]# source /etc/profile                                                  //加载环境变量使其立即生效
    [[email protected]~]#java -version
    [[email protected]~]#java version "1.8.0_60"
    Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
    Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

安装tomcat

    [[email protected]~]# tar xvf apache-tomcat-8.0.26.tar.gz -C /usr/local/
    [[email protected]~]# cd /usr/local/apache-tomcat-8.0.26/
    [[email protected] local]# mv   apache-tomcat-8.0.26/ tomcat/  为了方便启动
    [[email protected] ~]# chmod  -R 755 /etc/init.d/tomcat  赋予权限
    [[email protected]~]# vim /etc/init.d/tomcat
    #!/bin/bash
    # Tomcat init script for Linux
    # chkconfig: 2345 96 14
    # discription: The Apache Tomcat Server/JSP container
    JAVA_OPTS=‘-server -Xms64m -Xmx128m‘
    JAVA_HOME=/usr/java/jdk1.8.0_60
    CATALINA_HOME=/usr/local/tomcat
    $CATALINA_HOME/bin/catalina.sh $*
    [[email protected]~]# chkconfig --add tomcat
    [[email protected]~]# chkconfig tomcat on
    [[email protected]~]# netstat -antup | grep 8080                                             //查看是否启动
    tcp        0      0:::8080       :::*                 LISTEN      3154/java

测试Tomcat

浏览进行访问http://192.168.32.48:8080/ 

配置实验

为了达到实验要求 对nginx.conf进行调整:

    [[email protected] ~]# cat /usr/local/nginx/conf/nginx.conf
    user nginx nginx;
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
    listen         443 ssl;                                                  
  server_name    xuegod175.cn;#域名                          
  ssl_certificate      /usr/local/nginx/conf/server.crt;#证书路径      
  ssl_certificate_key   /usr/local/nginx/conf/server.key;#key路径              
  ssl_session_cache    shared:SSL:1m; #s储存SSL会话的缓存类型和大小                        
  ssl_session_timeout  5m; #会话过期时间                                               
  ssl_ciphers  HIGH:!aNULL:!MD5; #为建立安全连接,服务器所允许的密码格式列表                                          
  location / {
 root   html;
 index  index.html index.htm;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_pass http://192.168.42.176;
 proxy_redirect default;
        }
        }
    }
    [[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload
    Enter PEM pass phrase:

访问进行测试

注意:在访问测试之前  需要重启nginx 还有删除掉浏览器的缓存记录(不然很容易入坑。。。)

成功的访问到了192.168.42.176的界面 实验已经成功。

时间: 2024-08-30 10:14:54

(https)nginx - tomcat(http)的相关文章

Nginx自学手册(六)Nginx+Tomcat实现动静分离

(一)简述 Nginx是一种轻量级,高性能,多进程的Web服务器,非常适合作为静态资源的服务器使用,而动态的访问操作可以使用稳定的Apache.Tomcat及IIS等来实现,这里就以Nginx作为代理服务器的同时,也使用其作为静态资源的服务器,而动态的访问服务器就以Tomcat为例说明. (二)环境简介 服务器名称 IP 备注 Nginx服务器 192.168.180.4 Tomcat服务器 192.168.180.23 client 192.168.181.231 客户端访问 (三)具体步骤:

Nginx + Tomcat (N)集群配置

1 准备工作      CentOS 6.5  Nginx 1.8.0  Tomcat 8.0.24   备注: 1) CentOS,Nginx,Tomcat 下载.安装省略  2)Nginx (示例)路径: /usr/local/nginx-1.8.0  3)Tomcat (示例)路径: /usr/server/tomcat01 /usr/server/tomcat02 2  Nginx配置 1)进入nginx配置文件conf/nginx.conf  2)查看配置文件,不用修改,保持端口号为8

转】Nginx系列(五)--nginx+tomcat实现负载均衡

原博文出于:  http://blog.csdn.net/liutengteng130/article/details/47129909   感谢! Nginx占有内存少,并发能力强,事实上Nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用Nginx网站用户有:新浪,网易,腾讯,淘宝等. 以淘宝为例,进入淘宝主页,按F12.选择"NetWork" 本文主要是基于Nginx搭建tomcat集群. 环境: Win8.1,JDK 1.6 , Nginx1.9.3 Tom

Nginx系列(五)--nginx+tomcat实现负载均衡

Nginx占有内存少,并发能力强,事实上Nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用Nginx网站用户有:新浪,网易,腾讯等. 本文主要是基于Nginx搭建tomcat集群. 环境: Win8.1,JDK 1.6 , Nginx1.9.3 Tomcat 7.0.63(两个tomcat服务器) 结构: 一.Nginx之反向代理 1.Nginx配置: upstreamlocahost{ #ip_hash; server192.168.24.17:8080 weight=1

Nginx + Tomcat (java )服务器部署

Tomcat 是由 Apache 软件基金全下属的 Jakarta 项目开发的一个 Servlet 容器,按照Sun  Microsystems 提供的技术规范,实现了对 Servlet 和  JaveServer  Page ( JSP ) 的支持,Tomcat 本身也是一个 HTTP 服务器,主要用来解析 JSP  语言. TOMCAT 服务器的部署 安装环境: JDK +  TOMCAT 安装步骤: cd  /data wget  -c  http://download.oracle.co

MyEclipse2015 如何隐藏没用到的Server(MyEclipse Derby, MyEclipse Tomcat v7.0)

如下图所示,这两个server很烦,在MyEclipse2015版的Preferences里面又找不到地方去掉他们. 其实,要弄掉他们很简单: 哈哈-- (原创文章,转载请注明转自Clement-Xu的csdn博客.) 版权声明:本文为原创文章,转载请注明转自Clement-Xu的csdn博客.

nginx开启https(免费的二级域名也可以)

来源:https://www.cnblogs.com/DouglasLuo/p/12258331.html 最近疫情很严重,开学也被延迟了.于是在家很闲啊.碰巧,前几天我租了个域名,就想用研究一下如何搭建https. 这篇文章将用到一下内容: 一个域名,DNS已经解析到vps的ip地址(免费的二级域名也可以). 一台vps(没有vps用网站空间也可以,但不在这篇文章的讨论范畴). nginx(httpd不在这篇文章的讨论范畴). 首先在vps上安装nginx,并开启端口实现可以在外网访问通过80

android mvp高速开发框架介绍(dileber使用之图片下载工具)

这几天忙着工作- 今天抽时间又把框架的bug处理了一下--并且把volley的源代码改动了一下 android mvp框架:dileber(https://github.com/dileber/dileber.git) 官方交流qq群:171443726 我个人qq:297165331--有什么问题也能够咨询-- 继续解说dileber的图片下在工具 我改动了volley的NetworkImageView 的源代码--使得框架中的网络请求和图片请求都走一个接口 dileber中怎样使用下载图片的

Mac-MacOS降级(Mac系统降级,系统回退)

前言 最近把macOS更新到了 macOS Catalina,使用了一段时间后,结合自己的使用环境和体验,感觉 Catalina 不太好用,就想把系统回退到 macOS Mojave,但是平时几乎不用时间机器去备份,所以若想要回退版本,只有一个办法:下载“安装 macOS Mojave”应用程序, 制作引导盘,备份自己重要的东西(我的东西不多,40个G,直接拷贝到硬盘),抹掉数据重置Mac,通过引导盘,安装自己想要的系统. 然后自己先去官网(https://support.apple.com/z