http转https域名(lnmp)

本文详细介绍了如何在LNMP环境下将HTTP域名转换为HTTPS。步骤包括:下载SSL证书并上传至服务器,编辑Nginx配置文件添加HTTPS服务器块,并启用SSL设置,最后重启Nginx服务。

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

第一步:去云服务器平台下载ssl证书,下载下来解压后里面会有俩文件

第二步将这个文件放在一个文件夹里面比如叫cert.将改文件上传到服务器/usr/local/nginx/conf目录里

第三步:打开要加https的域名配置文件,将原来里面的整个server里面内容复制一份,放在原来那个server下边,如下.

server
    {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        server_name bus.tjgbank.cn;
        index index.html index.htm index.php book.php;
        root  /home/wwwroot/default/bus/public;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;
    location / {  
                if (!-e $request_filename) {  
                    rewrite ^(.*)$ /index.php?s=$1 last;  
                    break;  
                }  
            } 
       # location /
        #{
         #   try_files $uri $uri/ /index.php?$query_string;
       # }
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

server
    {
        listen 443;
        #listen [::]:80 default_server ipv6only=on;
        server_name bus.tjgbank.cn;
        index index.html index.htm index.php book.php;
        root  /home/wwwroot/default/bus/public;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;
    location / {  
                if (!-e $request_filename) {  
                    rewrite ^(.*)$ /index.php?s=$1 last;  
                    break;  
                }  
            } 
         ssl on;
         ssl_certificate   cert/a.pem;
         ssl_certificate_key  cert/a.key;
         ssl_session_timeout 5m;
         ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;
       # location /
        #{
         #   try_files $uri $uri/ /index.php?$query_string;
       # }
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

下边那个server里面ssl开头的是使https生效的关键部分。

第四步:保存退出然后service nginx restart重新就ok了!是不是so easy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值