如何在 Ubuntu 20.04 上使用 Nginx 安装 Grav CMS如何在 Ubuntu 20.04 上使用 Nginx 安装 Grav CMS如何在 Ubuntu 20.04 上使用 Nginx 安装 Grav CMS如何在 Ubuntu 20.04 上使用 Nginx 安装 Grav CMS
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

如何在 Ubuntu 20.04 上使用 Nginx 安装 Grav CMS

发表 admin at 2025年2月28日
类别
  • 未分类
标签

本教程适用于这些操作系统版本

  • Ubuntu 20.04(Focal Fossa)
  • Ubuntu 18.04(仿生海狸)

在此页

  1. 先决条件
  2. 开始
  3. 安装 Nginx 和 PHP
  4. 安装 Grav CMS
  5. 为 Grav CMS 配置 Nginx
  6. 访问 Grav CMS
  7. 使用 Lets Encrypt SSL 保护 Grav CMS
  8. 结论

Grav 是一个免费的、开源的、平面文件的 CMS,不需要任何数据库。它基于 PHP,并提供了其他 CMS(如 WordPress、Joomla 等)可能无法使用的多种功能。它简单易用,并附带一些关键技术,包括 Twig 模板、Markdown、YAML、 Parsedown、Doctrine Cache、Gregwar 图像库和 Symfony 控制台。

在本教程中,我将向您展示如何在 Ubuntu 20.04 服务器上使用 Nginx 和 Lets Encrypt SSL 安装 Grav CMS。

先决条件

  • 一台运行 Ubuntu 20.04 的服务器。
  • 用您的服务器 IP 指向的有效域名。
  • 在服务器上配置了根密码。

入门

首先,通过运行以下命令将系统包更新到更新版本:

apt-get update -y

更新所有包后,您可以继续下一步。

安装 Nginx 和 PHP

首先,您需要在系统中安装 Nginx Web 服务器、PHP 和其他 PHP 扩展。您可以使用以下命令安装所有这些:

apt-get install nginx php php-cli php-fpm php-common php-curl php-gd php-json php-mbstring php-xml php-zip php-opcache php-apcu unzip -y

安装所有包后,使用以下命令验证 PHP 版本:

php --version

您应该得到以下输出:

PHP 7.4.3 (cli) (built: Jul  5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

接下来,编辑 php.ini 文件并进行一些更改:

nano /etc/php/7.4/fpm/php.ini

更改以下行:

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = America/Chicago

保存并关闭文件,然后重新启动 PHP-FPM 服务以应用更改:

systemctl restart php7.4-fpm

完成后,您可以继续下一步。

安装重力 CMS

接下来,您需要将 Grav CMS 下载到 Nginx Web 根目录。您可以使用以下命令从 Grav 下载页面下载它:

cd /var/www/html
wget https://getgrav.org/download/core/grav-admin/1.7.17

下载完成后,使用以下命令解压缩下载的文件:

unzip 1.7.17

接下来,使用以下命令将提取的目录重命名为 grav:

mv grav-admin grav

接下来,为 grav 目录设置适当的所有权:

chown -R www-data:www-data /var/www/html/grav

完成后,您可以继续下一步。

为 Grav CMS 配置 Nginx

接下来,您需要创建一个 Nginx 虚拟主机配置文件来托管 Grav CMS。您可以使用以下命令创建它:

nano /etc/nginx/conf.d/grav.conf

添加以下行:

server {

listen 80;

server_name grav.example.com;
root /var/www/html/grav;

index index.html index.php;

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

   location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
   location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }

location ~ \.php$ {
   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 }

}

完成后保存并关闭文件,然后验证 Nginx 是否存在任何语法错误:

nginx -t

您应该得到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

最后,重新启动 Nginx 服务以应用更改:

systemctl restart nginx

您还可以使用以下命令验证 Nginx 的状态:

systemctl status nginx

您应该看到以下输出:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-09 06:45:28 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 33099 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 33110 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 33111 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.6M
     CGroup: /system.slice/nginx.service
             ??33111 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??33112 nginx: worker process

Jul 09 06:45:28 node1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 09 06:45:28 node1 systemd[1]: Started A high performance web server and a reverse proxy server.

一切正常后,您可以继续下一步。

访问重力 CMS

您现在可以使用 URL http://grav.example.com 访问 Grav CMS 网络用户界面。您应该看到以下屏幕:

设置您的管理员用户名和密码,然后单击“创建用户”按钮。您将被重定向到 Grav CMS 仪表板:

配置页

账户页面

插件页面

工具页面

使用 Lets Encrypt SSL 保护 Grav CMS

接下来,您需要安装 Certbot 客户端包来安装和管理 Lets Encrypt SSL。

首先,使用以下命令安装 Certbot:

apt-get install python3-certbot-nginx -y

安装完成后,运行以下命令在您的网站上安装 Lets Encrypt SSL:

certbot --nginx -d grav.example.com

您将被要求提供一个有效的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for grav.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/grav.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

键入 2 并按 Enter 键以完成安装。您应该看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/grav.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://grav.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=grav.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/grav.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/grav.example.com/privkey.pem
   Your cert will expire on 2021-12-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

您现在可以使用 HTTPS 协议安全地访问 Grav CMS。

结论

恭喜!您已经在 Ubuntu 20.04 服务器上成功安装了带有 Nginx 和 Lets Encrypt SSL 的 Grav CMS。您现在可以使用 Grav CMS 轻松创建您的网站。

©2015-2025 Norria support@alaica.com