0.说明

本文说描写叙述的方式是用nginx的443重定向到tomcat的8443,nginx的80port重定到tomcat的8080;

乱入:个人标记:caicongyang

1.nginx安装

能够參考我前面的文章:Linux tar包安装Nginx  ;http://blog.csdn.net/caicongyang/article/details/46388845

只是这篇文章中。我们编译的时候没有带ssl模块。因此须要又一次编译安装

须要在安装时带上ssl模块的选项

完毕命令例如以下:

#./configure --with-http_ssl_module 

当然你能够用下面命令查看全部的编译选项

#./configure --help

2.nginx生成免费证书

# cd /opt/nginx/sslkey/
# openssl genrsa -des3 -out server.key 1024
# openssl req -new -key server.key -out server.csr
# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

3.tomcat配置

server.xml
 <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="${user.home}/.
keystore" keystorePass="123456"/>

我的tomcat证书是又一次在生成的:(当前用户路径下)

#keytool -v -genkey -alias tomcat -keyalg RSA -keystore .keystore  -validity 36500

当然你也能够指定文件夹

#keytool -v -genkey -alias tomcat -keyalg RSA -keystore /opt/tomcat/sslkey/server.keystore  -validity 36500

当然你也能够在项目的web.xml中配置某个重要模块强制使用https,其它的模块正常走http

web.xml

 <security-constraint>
<web-resource-collection>
<web-resource-name>services</web-resource-name>
<url-pattern>/login/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

以上配置规定路径带login的所有走https

4.nginx配置

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; gzip on; upstream tomcat8080 {
server localhost:8080 weight=10;
} upstream tomcat8443 {
server localhost:8443 weight=10;
} server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
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://tomcat8080;
} #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;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server server {
listen 443;
server_name localhost; ssl on;
ssl_certificate /opt/nginx/sslkey/server.crt;
ssl_certificate_key /opt/nginx/sslkey/server.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
proxy_pass https://tomcat8443;
proxy_set_header Host $host:443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}

不懂运维的程序猿,不是好的project师!

我的个人站点:http://www.caicongyang.com

我的CSDN博客地址: http://blog.csdn.net/caicongyang


Nginx+tomcat+ssl免费证书配置的更多相关文章

  1. Nginx+Tomcat的服务器端环境配置详解

    这篇文章主要介绍了Nginx+Tomcat的服务器端环境配置详解,包括Nginx与Tomcat的监控开启方法,需要的朋友可以参考下 Nginx+tomcat是目前主流的Javaweb架构,如何让ngi ...

  2. Nginx+Tomcat+MemCached 集群配置手册

    系统实施文档 Nginx+Tomcat+MemCached 集群配置手册 目    录 第1章   概述 1.1   目标 互联网的快速发展带来了互联网系统的高负载和高可用性, 这要求我们在设计系统架 ...

  3. nginx支持ssl双向认证配置

    nginx支持ssl双向认证配置 listen 443; server_name test.com; ssl on; ssl_certificate server.crt; //server端公钥 s ...

  4. 阿里云https免费证书配置-包教会

      阿里云https免费证书配置-包教会-有需要请联系小编! 小编个人站点:https://www.itdog.site/ 小编微信号:wvqusrtg  

  5. CentOS 6.5 nginx+tomcat+ssl配置

    本文档用于指导在CentOS 6.5下使用nginx反向代理tomcat,并在nginx端支持ssl. 安装nginx.参见CentOS 6 nginx安装. SSL证书申请.参见腾讯SSL证书申请和 ...

  6. HappyAA服务器部署笔记1(nginx+tomcat的安装与配置)

    这是本人的服务器部署笔记.文章名称叫"部署笔记1"的原因是之后我对这个进行了改进之后,会有"部署笔记2","部署笔记3"...循序渐进,估计 ...

  7. centos安装配置nginx,ssl生产和配置教程

    [一]nginx安装nginx安装带ssl扩展: cd /usr/local/src #进入用户目录wget http://nginx.org/download/nginx-1.15.0.tar.gz ...

  8. 阿里云使用ssl免费证书

    购买免费证书 购买之后 申请证书 该域名必须添加一条TXT记录 根据提示添加记录 下载证书 我用的nginx做的映射,所以下载nginx nginx安装自行百度 将下载的文件解压到nginx目录下(创 ...

  9. nginx 安装SSL安全证书

    安装证书 文件说明: 1. 证书文件214051493730988.pem,包含两段内容,请不要删除任何一段内容. 2. 如果是证书系统创建的CSR,还包含:证书私钥文件214051493730988 ...

随机推荐

  1. Android RecyclerView实现横向滚动

    我相信很久以前,大家在谈横向图片轮播是时候,优先会选择具有HorizontalScrollView效果和ViewPager来做,不过自从Google大会之后,系统为我们提供了另一个控件Recycler ...

  2. jquery easyui a标记方法传值问题

    今天开发一个功能,其操作的按钮式是一个点击的a标记,并且是动态生成的,其点击方法需要传参数具体代码如下 {field:'time',title:'日程时间',width:200,align:'cent ...

  3. PostgreSQL备份与还原

    物理备份:整个数据库的数据目录及文件做备份:备份整个数据库的文件系统. 物理恢复:恢复整个数据库的文静系统. 物理备份方法: 开启归档 select pg_start_backup('backup—— ...

  4. <Sicily>Funny Game

    一.题目描述 Two players, Singa and Suny, play, starting with two natural numbers. Singa, the first player ...

  5. 编译报错一列----aclocal找不到

    编译源码包报错: 说aclocal这个命令找不到 解决: 使用 yum install -y automake问题解决

  6. windos下安装多个mysql服务

    最近需要使用Mysql制造大量数据,需要多个Mysql服务器.一开始的解决方案是使用多个windows机器.实体机不够,则用虚拟机来搞.但,,,,安装多个虚拟机…….好吧, 在网上查了下,有使用单个机 ...

  7. [POI2008]POD-Subdivision of Kingdom(搜索+状压)

    题意 给定一个n个点的无向图,要求将点集分成大小相等的两个子集,使两个子集之间的边数最少 (n<=26) 题解 一开始想了半天DP发现不会,去看题解全是搜索. 所以发现C(1326)可以过我就写 ...

  8. linux指令快速复制粘贴[龟速更新中]

    由于有经常碰到要输入linux指令,但是却忘记了的情况.在家里我把常用的命令放到Xshell的快速命令集,但是在很多情况下不在家,可能用的他人电脑,以及在非Win环境下使用ssh时没有xshell使用 ...

  9. 由防止表单重复提交引发的一系列问题--servletRequest的复制、body值的获取

    @Time:2019年1月4日 16:19:19 @Author:QGuo   背景:最开始打算写个防止表单重复提交的拦截器:网上见到一种不错的方式,比较合适前后端分离,校验在后台实现: 我在此基础上 ...

  10. Java基础学习总结(25)——Log4j快速入门教程

    log4j是一个优秀的日志组件,基本上所有的java开发项目都会用到它.下面将自己学习的一些心得总结一下,方便以后学习. log4j在项目中都不会单独使用,至少是我写过的java项目中没有.一般来说l ...