2

我从github克隆了 Directus 8 。我在本地服务器上运行它。它运行良好,没有任何问题。

然后我将代码上传到 AWS Elastic Beanstalk(PHP、apache)。但它显示 500 内部服务器错误。

错误日志:/var/www/html/directus/public/.htaccess: <IfModule not allowed here

我将.ebextensions/setup.config文件添加到我的根文件夹中,如下所示

files:          
  "/etc/httpd/conf.d/enable_mod_rewrite.conf": 
     mode: "644"
     owner: root
     group: root
     content: |
       AllowOverride All

但我的 Beanstalk 说Unsuccessful command execution on instance id(s) 'i-0f6...'. Aborting the operation.并进入了降级状态。

如何解决这个问题?

4

1 回答 1

1

此答案适用于 Directus 8 (PHP)

使用 .ebextensions 和 .platform 尝试了几乎所有的 apache 设置方式,但没有任何效果。

然后尝试使用自定义.platform配置的 NGINX。它奏效了。回答我所做的步骤可能对其有同样问题的其他人有所帮助


  1. Directus 文档有一些NGIEX 的配置,通过它

  2. 在文件夹nginex.conf下创建文件.platform/nginx

平台/nginx

  1. 我们将替换现有nginex.conf的豆茎内部。使用 ssh将现有复制nginex.conf到 ec2 实例并添加文档中提到的自定义配置并将其粘贴到我们新创建的.platform/nginx/nginex.conf

下面是我的习惯.platform/nginx/nginex.conf

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    32136;    
events {
    worker_connections  1024;
}    
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {
        listen 80 default_server;

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

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

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

        # Deny direct access to php files in extensions
        location /extensions/.+\.php$ {
            deny all;
        }
        
        # All uploads files (originals) cached for a year
        location ~* /uploads/([^/]+)/originals/(.*) {
            add_header Cache-Control "max-age=31536000";
        }

        # Serve php, html and cgi files as text file
        location ~* /uploads/.*\.(php|phps|php5|htm|shtml|xhtml|cgi.+)?$ {
            add_header Content-Type text/plain;
        }

        # Deny access to any file starting with .ht,
        # including .htaccess and .htpasswd
        location ~ /\.ht {
            deny all;
        }

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_index  index.php;
            include /etc/nginx/fastcgi.conf;                
        }        

        access_log    /var/log/nginx/access.log main;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}
  1. 完成后,当我们上传它时,beantalk 会自动将我们的 custom 替换nginex.conf为现有的nginex.conf. (注意:我们只能添加更改而不是替换,但在我尝试的时候它不起作用)
于 2021-03-20T03:28:29.310 回答