nginx配置https

该博客介绍了如何将从腾讯云下载的SSL证书配置到Nginx服务器上,以实现HTTPS服务。配置涉及将密钥文件放置在/etc/ssl/certs/目录下,并在Nginx配置文件中指定正确路径。配置包括两个server块,第一个将HTTP请求重定向至HTTPS,第二个处理HTTPS连接。此外,还设置了SSL协议、加密套件和其它性能优化选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

密钥文件

将从腾讯云下载的密钥文件放到服务器上,可放到如下目录

/etc/ssl/certs/

nginx配置文件如下
  http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server{
      listen 80;
      server_name xjtumbatest.cn;
      rewrite ^/(.*)$ https://xjtumbatest.cn:443/$1 permanent;
    }
    server{
      #监听443端口
      listen 443;
      server_name xjtumbatest.cn;
      ssl on;
      #从腾讯云获取到的第一个文件的全路径
      ssl_certificate /etc/ssl/certs/xjtumbatest.cn/1_xjtumbatest.cn_bundle.crt;
      #从腾讯云获取到的第二个文件的全路径
      ssl_certificate_key /etc/ssl/certs/xjtumbatest.cn/2_xjtumbatest.cn.key;
      ssl_session_timeout 5m;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
      ssl_prefer_server_ciphers on;
      root  /usr/share/nginx/html/stu_manage/public;
      index index.php index.html;
      #这是我的主页访问地址,因为使用的是静态的html网页,所以直接使用location就可以完成了。
      location / {
        index index.php index.html error/index.html;
        if (!-e $request_filename) {
          rewrite  ^(.*)$  /index.php?s=/$1  last;
        }
        autoindex  off;
      }
      location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
      }
    }
  }

共两个server
第一个是将80端口重定向到https,也就是443端口,http状态码是301,对用户是无感知的
在这里插入图片描述

第二个是https的,密钥文件路径不能填错
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值