美文网首页
# nginx https证书配置

# nginx https证书配置

作者: 阳光_8af8 | 来源:发表于2017-11-22 10:59 被阅读0次

nginx https证书配置

一 前言

此文档针对于nginx配置反向代理使用https证书方法

nginx作为反向代理服务器,将证书配置于nginx服务器上,与后端服务器采用http连接,前端采用https安全链接

二 配置步骤

1. 依赖:

nginx安装完成,并且80,443端口开放

2. 下载证书

在nginx目录下创建cert目录,下载证书至cert目录并解压

mkdir /etc/nginx/cert
cd /etc/nginx/cert
##下载证书至此
unzip 214033975830630.zip

3. 修改nginx配置文件

默认为/etc/nginx/nginx.conf,本文为vim /etc/nginx/include/123.conf 将其修改为 (以下属性中ssl开头的属性与证书配置有直接关系,其它属性请结合自己的实际情况复制或调整) :

server {
    listen 443;
    listen 80;
    server_name 123.hidc.com;
    ssl on;
set $mylight "";
     if ($http_accept_encoding ~* gzip) {
      set $mylight "gzip";
     }
    root html;
    index index.html index.htm;
    ssl_certificate   cert/214033975830630.pem;
    ssl_certificate_key  cert/214033975830630.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        #root   html;
        #index  index.html index.htm;
        gzip on;
        gzip_types text/plain application/x-javascript application/javascript text/css application/xml application/json;
         proxy_next_upstream http_502 http_504 error timeout invalid_header;
         #proxy_cache cache_one;
         #proxy_cache_valid 200 304 12h;
         #proxy_cache_key $host$uri$is_args$args;
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $remote_addr;
         proxy_pass http://webgis_server_cluster_https;
         #expires 1d;

    }
}

三 验证

重启nginx服务 /etc/init.d/nginx restart 打开浏览器访问https://123.hidc.com
如下图所示即可

四 配置nginx 同时支持http和https

同个域名支持 https 和 http 两种方式访问,可以如下配置文件:

server
     {
         listen 80;
         listen      443 ssl;   //修改后
         server_name  liu.test.com;
         location /
            {
              expires      302400s;

              proxy_pass   http://xxxx/xxxx/;            
                 }
              #ssl on;    //修改后
              ssl_certificate /usr/local/nginx/conf/server.crt;
              ssl_certificate_key /usr/local/nginx/conf/server.key;
              access_log  /usr/local/nginx/xxxx.log   log_access;

      }

五 强制使用https

若想强制使用https访问,对端口进行判断,然后rewrite即可。

if ($server_port != 443) {
    rewrite (.*) https://$host$1 permanent;
}

相关文章

  • # nginx https证书配置

    nginx https证书配置 一 前言 此文档针对于nginx配置反向代理使用https证书方法 nginx作为...

  • Nginx 配置 HTTPS

    使用Nginx配置HTTPS域名证书 安装SSL模块要在 nginx 中配置 https,就必须安装 ssl 模块...

  • nginx配置https

    nginx配置https https需要的证书我们已经申请到了,下面分享下nginx配置https的一些配置参数!...

  • Nginx环境下http和https(ssl)共存的方法

    给nginx配置SSL证书后(这里使用的是自己生成的测试证书,参见 nginx使用ssl模块配置HTTPS支持),...

  • Nginx配置https证书

    证书配置 配置http重定向https 主要是配置一个server,建议单独一个conf文件来配置。

  • Nginx 配置https证书

    参考文章: https://www.cnblogs.com/bincoding/p/6118270.html 1....

  • nginx配置https证书

    需要nginx开启http_ssl_module模块,基本上默认都开启 配置很简单直接上配置 获取https证书,...

  • autocert 与 nginx的配合

    autocert 负责生成SSL证书, 生成的证书配置在nginx中, nginx负责处理https请求. 使用a...

  • Nginx或tomcat8配置https

    前提申请免费域名https证书 一、nginx配置https并转发到tomcat 1、Nginx配置文件 2、 n...

  • Let’s Encrypt通配域名申请以及自动续期

    开始HTTPS之旅 获取Certbot客户端 生成证书 查看生产的证书 将证书用于nginx 在nginx的配置文...

网友评论

      本文标题:# nginx https证书配置

      本文链接:https://www.haomeiwen.com/subject/rljnvxtx.html