https证书设置以及设置301跳转

本文详细介绍了如何在Nginx中配置HTTPS证书,包括证书的放置位置、Nginx配置文件的修改,以及如何设置301跳转实现HTTP到HTTPS的重定向。此外,还讲解了如何启用文件压缩来提高网站性能。

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

https证书设置以及设置301跳转

1、在Nginx的安装目录下创建cert目录,并且将下载的全部文件拷贝到cert目录中。
2、打开 Nginx 安装目录下 conf 目录中的 nginx.conf 文件,找到:
HTTPS server
 server {
 listen 443;
server_name localhost;
ssl on;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
 location / {


}
}

3、将其修改为 (以下属性中ssl开头的属性与证书配置有直接关系,其它属性请结合自己的实际情况复制或调整) :
server {
 listen 443;
 server_name localhost;
 ssl on;
 root html;
 index index.html index.htm;
 ssl_certificate   /usr/local/nginx/conf/cert/www.baidu.com.pem;
 ssl_certificate_key  /usr/local/nginx/conf/cert/www.baidu.com.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;
 }
}

 

4、设置301跳转,实现http与https看起来像同一个网站
server
    {
        listen 80;
        server_name  www.baidu.com baidu.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root /home/www/baidu;
        return 301 https://www.baidu.com$request_uri;
}

 

5、启用文件压缩
#-------gzip conf-----
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";

 

基本只需要更改gzip_comp_level等级,1-9,等级越高压缩率越高,但相应也越耗CPU资源,一般不会设置可以折中为6.

6、重启nginx服务
./nginx -s reload
systemctl nginx restart

 

 

转载于:https://www.cnblogs.com/roes/p/10406270.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值