NGINX 配置 HTTPS

2 篇文章 0 订阅
2 篇文章 0 订阅

1、购买SSL证书(腾讯云为例)

在这里插入图片描述


2、绑定域名后下载证书到本地

在这里插入图片描述


3、上传证书到服务器,修改NGINX配置文件

user root;
worker_processes        auto;
worker_rlimit_nofile    204800;

events {
    use epoll;
    worker_connections  1024;
    accept_mutex        on;
    multi_accept        on;
}

http {
    limit_req_zone      $binary_remote_addr zone=one:10m rate=2r/s;
    include             mime.types;
    default_type        application/octet-stream;
    server {
        listen		    8001;
        server_name	    【你的域名】;
        rewrite		    ^(.*)$ https://$host$1 permanent;
    }

    server {
        listen              	    443 ssl;
	    server_name         	    【服务器IP地址】;
	    root                	    /data/dist;
        port_in_redirect    	    off;
	    ssl_certificate      	    【上一步上传的证书里的_bundle.crt结尾的证书】;
	    ssl_certificate_key  	    【上一步上传的证书里的.key结尾的文件】;;

	    ssl_session_cache    	    shared:SSL:1m;
	    ssl_session_timeout  	    5m;

	    ssl_ciphers 			    HIGH:!aNULL:!MD5;
	    ssl_prefer_server_ciphers  	on;

        location / {
            index                   index.html index.htm;
            try_files               $uri $uri/ /index.html;
        }

        location /maintain/api/ {
            limit_req   zone=one burst=5 nodelay;
       	    proxy_pass  http://192.168.50.151:8080/maintain/api/;
        }

        location /file/ {
            alias                       "/data/ftp/back_up/";
            autoindex                   on;
            autoindex_localtime         on;
            autoindex_format            html;
            autoindex_exact_size        off;
            charset                     utf-8,gbk;
            auth_basic                  "admin";
            auth_basic_user_file        "/data/nginx/htpasswd";
        }

        location /log/ {
            alias                       "/data/cloud/log/";
            autoindex                   on;
            autoindex_localtime         on;
            autoindex_format            html;
            autoindex_exact_size        off;
            charset                     utf-8,gbk;
	        add_header Content-Type     "text/plain;charset=utf-8";
            auth_basic                  "admin";
            auth_basic_user_file        "/data/nginx/htpasswd";
        }
    }
}

4、重新加载NGINX配置

/data/nginx/sbin/nginx -s reload

5、开放443端口(HTTPS默认使用443端口)

iptables -I INPUT -p tcp --dport 443 -j ACCEPT
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值