NGINX Unit

Drupal§

使用 Unit 运行 Drupal 内容管理系统

  1. 使用 PHP 语言模块安装 Unit

  2. 安装和配置 Drupal 的 先决条件

  3. 安装 Drupal 的 核心文件。在此,我们将其安装在 /path/to/app/;在您的配置中使用真实路径。

  4. 运行以下命令,以便 Unit 可以访问 应用程序目录

    # chown -R unit:unit /path/to/app/
    

    注意

    unit:unit 用户组对仅适用于 官方软件包、Docker 镜像 和某些 第三方仓库。否则,帐户名称可能有所不同;运行 ps aux | grep unitd 命令以确保。

    有关更多详细信息,包括权限,请参阅 安全检查清单

  5. 接下来,准备 Drupal 配置以供 Unit 使用。Drupal 安装中的默认 .htaccess 方案 大致转换为以下内容(对 shareroot 使用真实值)

    {
        "listeners": {
            "*:80": {
                "pass": "routes"
            }
        },
    
        "routes": [
            {
                "match": {
                    "uri": [
                        "!*/.well-known/*",
                        "/vendor/*",
                        "/core/profiles/demo_umami/modules/demo_umami_content/default_content/*",
                        "*.engine",
                        "*.inc",
                        "*.install",
                        "*.make",
                        "*.module",
                        "*.po",
                        "*.profile",
                        "*.sh",
                        "*.theme",
                        "*.tpl",
                        "*.twig",
                        "*.xtmpl",
                        "*.yml",
                        "*/.*",
                        "*/Entries*",
                        "*/Repository",
                        "*/Root",
                        "*/Tag",
                        "*/Template",
                        "*/composer.json",
                        "*/composer.lock",
                        "*/web.config",
                        "*sql",
                        "*.bak",
                        "*.orig",
                        "*.save",
                        "*.swo",
                        "*.swp",
                        "*~"
                    ]
                },
    
                "action": {
                    "return": 404
                }
            },
            {
                "match": {
                    "uri": [
                        "/core/authorize.php",
                        "/core/core.api.php",
                        "/core/globals.api.php",
                        "/core/install.php",
                        "/core/modules/statistics/statistics.php",
                        "~^/core/modules/system/tests/https?\\.php",
                        "/core/rebuild.php",
                        "/update.php",
                        "/update.php/*"
                    ]
                },
    
                "action": {
                    "pass": "applications/drupal/direct"
                }
            },
            {
                "match": {
                    "uri": [
                        "!/index.php*",
                        "*.php"
                    ]
                },
    
                "action": {
                    "return": 404
                }
            },
            {
                "action": {
                    "share": "/path/to/app/web$uri",
                    "fallback": {
                        "pass": "applications/drupal/index"
                    }
                }
            }
        ],
    
        "applications": {
            "drupal": {
                "type": "php",
                "targets": {
                    "direct": {
                        "root": "/path/to/app/web/"
                    },
    
                    "index": {
                        "root": "/path/to/app/web/",
                        "script": "index.php"
                    }
                }
            }
        }
    }
    

    注意

    pass 目标之间的区别在于它们对 script 设置 的使用

    • direct 目标从 URI 运行 .php 脚本,如果 URI 省略它,则运行 index.php

    • index 目标指定 Unit 为目标接收的任何 URI 运行的 script

  6. 上传更新的配置。假设上述 JSON 已添加到 config.json

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    注意

    控制套接字 路径可能有所不同;运行 unitd -h 或参阅 启动和关闭 了解详情。

    成功更新后,浏览至 http://localhost设置 Drupal 安装

Drupal on Unit - Setup Screen