• linux下nginx配置ssl证书(https)


    本文转自:91博客;原文地址:http://www.9191boke.com/320666118.html

    nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示:

    xxx.crt;   #(证书公钥)
    xxx.key;  #(证书私钥)

    把这两个文件放到nginx的conf文件夹下

    打开nginx配置文件,添加配置段:

     nginx.conf全部内容如下:

    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_api {  
            server 127.0.0.1:8080  weight=1;
        }
        
        server {
            listen       80;
            server_name  huituanquan.com;
            #http转https(前提是已经配置nginx ssl证书)
            rewrite ^(.*)$  https://$host$1 permanent;
        }
        
        # HTTPS 
        server {  
            listen 443;  
            server_name huituanquan.com;                         #网站域名
          
            ssl on;  
            ssl_certificate huituanquan.com-ca-bundle.crt;         #(证书公钥)
            ssl_certificate_key huituanquan.com.key;             #(证书私钥)

          ssl_session_timeout 5m;
          #ssl_protocols SSLv2 SSLv3 TLSv1;
          ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
          #ssl_ciphers HIGH:!aNULL:!MD5;
          ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
          ssl_prefer_server_ciphers on;

    
            location / {
                proxy_pass http://tomcat8080_api;  
                proxy_redirect default;      
                #设置主机头和客户端真实地址,以便服务器获取客户端真实IP
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            } 
        }
    
    }

    最后重启nginx即可

    /alidata/server/nginx/sbin/nginx -s reload
  • 相关阅读:
    eslint and stylelint config
    CSS3 animaion 和 transition 比较
    css之px、em、rem
    Three.js 中 相机的常用参数含义
    ES6中函数调用自身需要注意的问题
    MySQL数据库迁移之data目录
    ES6扩展运算符(三点运算符)...的用法
    Vue 组件通信方案
    关于ES6中Promise的应用-顺序合并Promise,并将返回结果以数组的形式输出
    Ubuntu 使用gps
  • 原文地址:https://www.cnblogs.com/007sx/p/8317325.html
Copyright © 2020-2023  润新知