内容纲要

克隆 letsencrypt

ubuntu 下


git clone https://github.com/letsencrypt/letsencrypt

cd letsencrypt

./certbot-auto --help all

# 生成证书时需要停掉 nginx, certbot-auto 会占用 80 端口,生成完再开启 nginx
./certbot-auto certonly --standalone --email wyrover@gmail.com -d www.dev798.com -d wiki.dev798.com

生成证书时需要停掉 nginx, certbot-auto 会占用 80 端口,生成完再开启 nginx

nginx 配置


server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl on;
    server_name www.dev798.com;

    ssl_certificate   /etc/letsencrypt/live/www.dev798.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/www.dev798.com/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    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;

    root /var/www/wordpress;
    index index.php index.html;

    log_not_found off;
    access_log /var/log/nginx/www.dev798.com.access.log;
    error_log /var/log/nginx/www.dev798.com.error.log;

    charset utf-8;

    location / {        
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {     
        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
        }

        if (-f $request_filename/index.php) {
            rewrite (.*) $1/index.php;
        }

        if (!-f $request_filename) {
            rewrite (.*) /index.php;
        }

        if (!-e $request_filename) {
            return 404;
        }
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;        
    }  

}

server {
    listen 80;
    server_name www.dev798.com;

    root /var/www/wordpress;
    index index.php index.html;

    log_not_found off;
    access_log /var/log/nginx/www.dev798.com.access.log;
    error_log /var/log/nginx/www.dev798.com.error.log;

    charset utf-8;

    location / {        
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {     
        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
        }

        if (-f $request_filename/index.php) {
            rewrite (.*) $1/index.php;
        }

        if (!-f $request_filename) {
            rewrite (.*) /index.php;
        }

        if (!-e $request_filename) {
            return 404;
        }
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;        
    }  

}

自动续期

./certbot-auto certonly --renew-by-default --email wyrover@gmail.com -d www.dev798.com -d wiki.dev798.com

发表评论

电子邮件地址不会被公开。 必填项已用*标注