nginx支持http 和https共存

简介:

实验环境:

[root@node03 ~]# cat /etc/redhat-release 

CentOS release 6.6 (Final)

[root@node03 ~]# uname -a

Linux node03 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[root@node03 ~]#

主机IP地址:

ngixn 192.168.112.130

node01 192.168.112.128

node02 192.168.112.129

[root@node03 package]# ll -rth nginx-1.10.2.tar.gz 

-rw-r--r-- 1 root root 890K Dec  7 06:30 nginx-1.10.2.tar.gz

[root@node03 package]# 


nginx安装:

[root@node03 ~]# yum -y install pcre pcre-devel

[root@node03 nginx-1.10.2]#./configure --prefix=/usr/local/product/nginx1.10.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

[root@node03 ~]# 

配置文件:

[root@node03 conf]# vim nginx.conf

user  root;

worker_processes 4;

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

    server_tokens off;


   include /usr/local/nginx/conf/conf.d/*.conf;

}

[root@node03 conf]#

[root@node03 conf.d]# cat log.cloud.ucode.com.conf 

upstream log_cloud_backend {

        server 192.168.112.128:8080;

       server 192.168.112.129:8080;

}

server {

        listen          80;   #--------------->http请求

        listen          443 ssl;#-------------->https请求

        server_name     log.cloud.ucode.com;

        ssl_certificate       /usr/local/nginx/sslcrt/log/server.crt;#证书

        ssl_certificate_key   /usr/local/nginx/sslcrt/log/server.key;#解密证书的key

        ssl_protocols SSLv2 SSLv3 TLSv1;

        ssl_prefer_server_ciphers on;

        ssl_ciphers ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 

        access_log  /usr/local/nginx/logs/log.cloud.ucode.com.log;

        error_log   /usr/local/nginx/logs/error.cloud.ucode.com.log;

        location / {

                proxy_set_header Host $http_host;

                proxy_set_header X-Real-IP $remote_addr;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                proxy_pass http://log_cloud_backend;            

                proxy_http_version 1.1;  

                proxy_set_header Upgrade $http_upgrade;

                proxy_set_header Connection "Upgrade";

                proxy_redirect off;

        }

    }

[root@node03 conf.d]#


具体证书的申请这里就不在详细叙述,网上很多介绍,然后通过如下连接访问即可

http://log.cloud.ucode.com

https://log.cloud.ucode.com







      本文转自027ryan  51CTO博客,原文链接:http://blog.51cto.com/ucode/1884756,如需转载请自行联系原作者




相关文章
|
12天前
|
数据可视化 关系型数据库 MySQL
ELK实现nginx、mysql、http的日志可视化实验
通过本文的步骤,你可以成功配置ELK(Elasticsearch, Logstash, Kibana)来实现nginx、mysql和http日志的可视化。通过Kibana,你可以直观地查看和分析日志数据,从而更好地监控和管理系统。希望这些步骤能帮助你在实际项目中有效地利用ELK来处理日志数据。
177 90
|
4月前
|
缓存 应用服务中间件 网络安全
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
281 7
|
3月前
|
Ubuntu Linux Shell
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
(已成功解决)Linux环境报错—bash: wget: command not found;常见Linux发行版本,Linux中yum、rpm、apt-get、wget的区别;Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
1018 68
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
|
1月前
|
网络协议 安全 网络安全
Introduction to the HTTP and HTTPS Protocol
HTTP protocol is the foundation of the Internet, and HTTPS is the secure version of HTTP. HTTP is an application layer protocol based on TCP/IP protocol. It does not involve packet (packet) transmission, mainly specifying the communication format between the client and the server, and the default po
75 25
|
1月前
|
缓存 安全 网络安全
代理协议解析:如何根据需求选择HTTP、HTTPS或SOCKS5?
本文详细介绍了HTTP、HTTPS和SOCKS5三种代理协议的特点、优缺点以及适用场景。通过对比和分析,可以根据具体需求选择最合适的代理协议。希望本文能帮助您更好地理解和应用代理协议,提高网络应用的安全性和性能。
66 17
|
2月前
|
缓存 负载均衡 应用服务中间件
Nginx七层(应用层)反向代理:HTTP反向代理proxy_pass篇
通过使用Nginx的反向代理功能,可以有效地提高Web应用的性能、安全性和可扩展性。配置过程中需要注意不同场景下的具体需求,如负载均衡、SSL终止和缓存策略等。正确配置和优化Nginx反向代理可以显著提升系统的整体表现。
405 20
|
2月前
|
安全 搜索推荐 网络安全
HTTPS与HTTP:区别及安全性对比
HTTP和HTTPS是现代网络通信中的两种重要协议。HTTP为明文传输,简单但不安全;HTTPS基于HTTP并通过SSL/TLS加密,确保数据安全性和完整性,防止劫持和篡改。HTTPS还提供身份验证,保护用户隐私并防止中间人攻击。尽管HTTPS有额外的性能开销和配置成本,但在涉及敏感信息的场景中,如在线支付和用户登录,其安全性优势至关重要。搜索引擎也更青睐HTTPS网站,有助于提升SEO排名。综上,HTTPS已成为大多数网站的必然选择,以保障用户数据安全和合规性。
137 1
|
3月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
1118 8
|
3月前
|
安全 算法 网络安全
HTTP和HTTPS的区别
本文介绍HTTP与HTTPS的区别、HTTPS链接建立过程及常见加密算法。HTTP为明文传输,易被窃听;HTTPS通过SSL/TLS协议加密,确保数据安全。HTTPS使用端口443,提供认证机制。文中还详细讲解了对称加密(如AES、DES)和非对称加密(如RSA、ECC)算法的特点及应用场景。
|
4月前
|
缓存 安全 网络安全
HTTP/2与HTTPS在Web加速中的应用
HTTP/2与HTTPS在Web加速中的应用
132 11