nginx证书制作以及配置https并设置访问http自动跳转https

默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中。通常这个文件名类似libssl-dev。

生成证书

可以通过以下步骤生成一个简单的证书:
首先,进入你想创建证书和私钥的目录,例如:

$ cd /usr/local/nginx/conf

创建服务器私钥,命令会让你输入一个口令:

$ openssl genrsa -des3 -out server.key
1024

创建签名请求的证书(CSR):

$ openssl req -new -key server.key -out
server.csr

具体方法请参考

SSL证书生成方法 - fyang的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/fyang2007/article/details/6180361

在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

$ cp server.key server.key.org

$ openssl rsa -in server.key.org -out
server.key

配置nginx

最后标记证书使用上述私钥和CSR:

$ openssl x509 -req -days 365 -in
server.csr -signkey server.key -out server.crt

修改Nginx配置文件,让其包含新标记的证书和私钥:

server {

server_name
YOUR_DOMAINNAME_HERE;

listen 443;

ssl on;

ssl_certificate
/usr/local/nginx/conf/server.crt;

ssl_certificate_key
/usr/local/nginx/conf/server.key;

}

重启nginx。
这样就可以通过以下方式访问:

https://YOUR_DOMAINNAME_HERE

另外还可以加入如下代码实现80端口重定向到443

server {

listen 80;

server_name ww.centos.bz;

rewrite
^(.*) https://$server_name$1 permanent;

}

转载请注明文章来源:http://www.centos.bz/2011/12/nginx-ssl-https-support/

反向代理设置

upstream jboss{

#ip_hash;

sticky;

server
10.70.xx.119:8080  max_fails=3  fail_timeout=20s;

server
10.70.xx.120:8080  max_fails=3  fail_timeout=20s;

check
interval=3000 rise=2 fall=5 timeout=1000;

}

location / {

proxy_pass http://jboss;

proxy_next_upstream http_500 http_502
http_503 error timeout invalid_header;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 328k;

#proxy_buffering off

#proxy_connect_timeout 90;

#proxy_send_timeout 90;

#proxy_read_timeout 90;

proxy_buffer_size 320k;

proxy_buffers 4 320k;

proxy_busy_buffers_size 640k;

proxy_temp_file_write_size 640k;

}

完整nginx.conf配置

vi nginx.conf

#user 
nobody;

worker_processes  2;

#error_log 
logs/error.log;

#error_log 
logs/error.log  notice;

#error_log 
logs/error.log  info;

#pid       
logs/nginx.pid;

events {

use
epoll;

worker_connections  65536;

}

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"';

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 jboss{

#ip_hash;

sticky;

server
10.70.xx.119:8080  max_fails=3  fail_timeout=20s;

server
10.70.xx.120:8080  max_fails=3  fail_timeout=20s;

check
interval=3000 rise=2 fall=5 timeout=1000;

}

server {

listen       80;

server_name  10.72.16.112;

#rewrite
^(.*) https://$10.72.16.112$1 permanent;

rewrite
^(.*) https://$server_name$1 permanent;

location
/ {

proxy_pass http://jboss;

proxy_next_upstream http_500 http_502
http_503 error timeout invalid_header;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 328k;

#proxy_buffering off

#proxy_connect_timeout 90;

#proxy_send_timeout 90;

#proxy_read_timeout 90;

proxy_buffer_size 320k;

proxy_buffers 4 320k;

proxy_busy_buffers_size 640k;

proxy_temp_file_write_size 640k;

}

location /nginx-status{

allow 10.0.0.0/8;

deny all;

stub_status on;

access_log off;

}

location
/nstatus {

check_status;

access_log
off;

}

#charset koi8-r;

#access_log  logs/host.access.log  main;

#location / {

#    root   html;

#    index  index.html index.htm;

#}

#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 ssl;

#    server_name  localhost;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;

#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#   
ssl_prefer_server_ciphers  on;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

server {

listen       443 ssl;

server_name  localhost;

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

ssl_certificate      /home/proadmin/nginx/ssl/server.crt;

ssl_certificate_key 
/home/proadmin/nginx/ssl/server.key;

ssl_session_cache   
shared:SSL:1m;

ssl_session_timeout  5m;

ssl_ciphers  HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers  on;

access_log  logs/jboss.log  main;

location / {

proxy_pass http://jboss;

proxy_next_upstream http_500 http_502 http_503 error timeout
invalid_header;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 328k;

#proxy_buffering off

#proxy_connect_timeout 90;

#proxy_send_timeout 90;

#proxy_read_timeout 90;

proxy_buffer_size 320k;

proxy_buffers 4 320k;

proxy_busy_buffers_size 640k;

proxy_temp_file_write_size 640k;

}

}

}

nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)的更多相关文章

  1. 【转载】网站配置Https证书系列(三):IIS网站设置Http链接直接跳转Https安全连接

    Http链接请求是以明文的方式传输,在传输的过程中很容易被篡改数据,一个典型的例子就是运营商的网络劫持注入广告信息等,而Https请求则是安全加密的请求,报文数据以密文的形式进行传输.当IIS网站配置 ...

  2. Tomcat的Https设置及Http自动跳转Https

    Https相关介绍    Https是由NetScape公司设计的一个基于Http的加密传输协议,可以这样理解Https = Http +SSL(安全套接层),Https的端口为443,而且还需要申请 ...

  3. 设置HTTP请求自动跳转HTTPS

    第一种方式,分两种情况: 第一种情况:修改Nginx安装目录/conf/nginx.conf文件 server { listen 80; server_name localhost; #将localh ...

  4. Tomcat 服务器安装 SSL证书,实现 HTTP 自动跳转 HTTPS

    本文以阿里云为例: 一.下载证书 1.1.登录阿里云:https://www.aliyun.com/ 1.2.控制台搜索:SSL证书 1.3.进入 SSL证书控制台 1.4.申请免费 SSL证书,已有 ...

  5. IIS服务器设置http自动跳转https方法

    很多站长在部署SSL证书后,网站实现https加密访问,但考虑到用户习惯了http访问,很多外链也是http访问形式,所以需要在IIS服务器配置http自动跳转https,避免用户通过http访问不到 ...

  6. chrome解决http自动跳转https问题

    1.地址栏输入: chrome://net-internals/#hsts 2.找到底部Delete domain security policies一栏,输入想处理的域名,点击delete. 3.搞 ...

  7. Tomcat配置https及访问http自动跳转至https

    https介绍:   HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全 ...

  8. tomcat设置http自动跳转为https访问

    一.生成服务器端证书文件 可以使用Windows系统或者Linux系统 (1)Windows环境 条件:已经安装JDK 步骤: 1.在运行里输入cmd进入命令窗口 2.进入JDK安装目录  如D:/P ...

  9. https----------如何在phpstudy环境下配置apache的https访问以及访问http自动跳转成https

    1.首先在 httpd.conf里面修改几个地方 找到 #LoadModule ssl_module modules/mod_ssl.so 去掉前面的# Include conf/vhosts.con ...

随机推荐

  1. H Hip To Be Square Day5——NWERC2012

    这个题目巨坑啊.调试的时间加起来绝对超过1天整. 不过终于调试出来了,真心感动地尿流满面啊. 题目的意思是给你一个区间[A,B],可以从区间里选出任意多个整数,使得这些整数的积是一个不超过 2^126 ...

  2. 转---秒杀多线程第十四篇 读者写者问题继 读写锁SRWLock

    在<秒杀多线程第十一篇读者写者问题>文章中我们使用事件和一个记录读者个数的变量来解决读者写者问题.问题虽然得到了解决,但代码有点复杂.本篇将介绍一种新方法——读写锁SRWLock来解决这一 ...

  3. 洛谷P1345 [USACO5.4]奶牛的电信(最小割)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  4. QVariant实质

    QVariant实质 QVariant是一种可以存储不同类型的数据结构,在很多场合这是很有用得为了达到这种目的,可以想象,该对象应该存储对象的类型信息,数据信息以及其他辅助详细考虑用途,这种对象必须支 ...

  5. Javascript面向对象三大特性(封装性、继承性、多态性)详解及创建对象的各种方法

    Javascript基于对象的三大特征和C++,Java面向对象的三大特征一样,都是封装(encapsulation).继承(inheritance )和多态(polymorphism ).只不过实现 ...

  6. [SDOI2011]黑白棋 kth - nim游戏

    题面 题面 题解 观察题目,我们可以发现,这个游戏其实就是不断再把对方挤到一边去,也就是黑子不断往左走,白子不断往右走. 因此可以发现,如果将黑白子按顺序两两配对,那么它们中间的距离会不断缩小,且每次 ...

  7. Closest Number in Sorted Array

    Given a target number and an integer array A sorted in ascending order, find the index i in A such t ...

  8. P3620 [APIO/CTSC 2007]数据备份

    P3620 [APIO/CTSC 2007]数据备份 题目描述 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味的,因此你想设计一个系统让不同 ...

  9. LeakCanary原理分析

    参考文档 http://blog.csdn.net/wyfei021/article/details/46506521http://vjson.com/wordpress/leakcanary%e6% ...

  10. Mac(Linux)上安装memcached步骤

    Mac上安装memcached类似于在Linux平台上安装memcached. 主要需要做两块: 一.安装libevent库: 二.安装memcached; 一.安装libevent库 libeven ...