ubuntu 20.04更换网站服务器apache为nginx

首先停用apache

systemctl stop apache2

安装nginx和php-fpm

apt install nginx php-fpm

创建nginx配置文件 nano /etc/nginx/sites-available/zrdn.conf

server {
    listen 80;
    server_name zuoridangnian.com;
    root /var/www/zrdn;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

启用站点

ln -s /etc/nginx/sites-available/zrdn.conf /etc/nginx/sites-enabled

重启nginx

systemctl restart nginx

配置ssl证书,安装certbot nginx

apt-get install certbot python3-certbot-nginx

配置证书

certbot –nginx

选择域名,然后选择第二项,renew 更新证书,然后因为我用了cloudflare的cdn,所以选择No Redirect

如果你也用了cloudflare 并且ssl是flexible模式,则你vps其实可以不用安装ssl证书

重载一下nginx,大功告成

systemctl restart nginx