SSL lnmp HTTPS 配置实例

配置实例

server
    {
        listen 80;
        #listen [::]:80;
        server_name abc.com www.abc.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/abc.com;

        include rewrite/wordpress.conf;
        #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 ~ .*\.(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/abc.com.log;
    }

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name abc.com www.abc.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/abc.com;

        ssl_certificate /home/wwwroot/abc.com/ssl/10092807_yundapm.com.pem;
        ssl_certificate_key /home/wwwroot/abc.com/ssl/10092807_yundapm.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

        include rewrite/wordpress.conf;
        #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 ~ .*\.(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/abc.com.log;
    }

LNMP 环境(Linux + Nginx + MySQL + PHP)中配置 SSL 证书,你可以按照以下步骤进行操作: 1. 获取 SSL 证书:你可以购买 SSL 证书或使用免费的工具(如 Let's Encrypt)来获取证书。确保你获得了证书文件(通常是以 `.crt` 结尾)和私钥文件(通常是以 `.key` 结尾)。 2. 将证书和私钥文件放置在服务器上:将证书和私钥文件上传到服务器上的安全目录中,例如 `/etc/nginx/ssl/`。 3. 配置 Nginx:找到 Nginx 的虚拟主机配置文件(通常位于 `/etc/nginx/conf.d/your_site.conf`),并进行以下修改: ``` server { listen 443 ssl; server_name your_domain.com; ssl_certificate /etc/nginx/ssl/your_certificate.crt; ssl_certificate_key /etc/nginx/ssl/your_private_key.key; # 可选:为了增加安全性,你可以配置其他 SSL 相关的设置,例如: # ssl_protocols, ssl_ciphers, ssl_prefer_server_ciphers, ssl_session_cache 等 location / { root /path/to/your/web/files; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php<version>-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 将 `your_domain.com` 替换为你的域名,将 `/etc/nginx/ssl/your_certificate.crt` 和 `/etc/nginx/ssl/your_private_key.key` 替换为你实际的证书和私钥文件的路径。将 `/path/to/your/web/files` 替换为你网站文件的实际路径。将 `<version>` 替换为你安装的 PHP 版本号。 4. 重启 Nginx:保存并关闭配置文件后,使用以下命令重启 Nginx 以使配置生效: ``` sudo systemctl restart nginx ``` 完成以上步骤后,你的 LNMP 环境将通过 HTTPS 提供安全连接,并且能够处理 PHP 文件。请确保在防火墙中打开了 443 端口,并在 DNS 中正确地将域名指向你的服务器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值