lxc 与 nextcloud 和 nginx 代理:未知:POST Content-Length

Posted

技术标签:

【中文标题】lxc 与 nextcloud 和 nginx 代理:未知:POST Content-Length【英文标题】:lxc with nextcloud and nginx proxy: Unknown: POST Content-Length 【发布时间】:2020-04-30 10:54:54 【问题描述】:

我有两个 lxc 容器。一个是带有 nginx 的代理和这个配置:

server 

    server_name cloud.malte-kiefer.de;

    location / 
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://cloud.lxd;
    

    real_ip_header proxy_protocol;
    set_real_ip_from 127.0.0.1;

    listen [::]:443 ssl http2 proxy_protocol; 
    listen 443 ssl http2 proxy_protocol; 
    ssl_certificate /etc/nginx/ssl/cloud.malte-kiefer.de/fullchain.cer; 
    ssl_certificate_key /etc/nginx/ssl/cloud.malte-kiefer.de/privkey.key; 



server 
    listen 80 proxy_protocol;
    listen [::]:80 proxy_protocol;

    server_name cloud.malte-kiefer.de;


    location / 
        return 301 https://cloud.malte-kiefer.de$request_uri;
    

    return 404;

然后我有了带有这个配置的 nextcloud 的云容器:

upstream php-handler 
    server unix:/var/run/php/php7.3-fpm.sock;


server 
    listen 80 default_server;
    listen [::]:80 default_server;
    set $base /var/www/html;
    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name cloud.malte-kiefer.de;


    fastcgi_hide_header X-Powered-By;

    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Enable gzip but do not remove ETag headers
    gzip on;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_min_length 256;
    gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
    gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;


        location = /robots.txt 
            allow all;
        log_not_found off;
        access_log off;
    

    location / 
        rewrite ^ /index.php;
    

    location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ 
        deny all;
    
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) 
        deny all;
    

    location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) 
        fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
        set $path_info $fastcgi_path_info;
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    

    location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) 
        try_files $uri/ =404;
        index index.php;
    

    location = /.well-known/carddav 
      return 301 https://cloud.malte-kiefer.de/remote.php/dav;
    
    location = /.well-known/caldav 
      return 301 https://cloud.malte-kiefer.de/remote.php/dav;
    

    location ~ \.(?:css|js|woff2?|svg|gif|map)$ 
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463";
        add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;

        # Optional: Don't log access to assets
        access_log off;
    

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ 
        try_files $uri /index.php$request_uri;
        # Optional: Don't log access to other assets
        access_log off;
    

当我尝试打开 URL 时,我会看到来自 nextcloud 的安装页面。当我输入信息并将其从页面重新加载并在 nextcloud 日志中发送时:

未知:213 字节的 POST 内容长度超过了 16 字节的限制 Unknown#0 处的字节数

这是来自 nextcloud 容器的 nginx 日志

2020/01/13 17:32:20 [错误] 416#416: *8 FastCGI 在标准错误中发送:“PHP 消息:PHP 警告:未知:POST 内容长度为 213 个字节 读取时超过第 0 行未知中 16 字节的限制 来自上游的响应标头,客户端:89.204.135.199,服务器: cloud.malte-kiefer.de,请求:“POST /index.php HTTP/1.0”,上游: “fastcgi://unix:/var/run/php/php7.3-fpm.sock:”,主机: “cloud.malte-kiefer.de”

我检查了我的 PHP ini 文件:

root@cloud:~# grep -R "post_max_size" /etc/php/
/etc/php/7.3/fpm/php.ini:post_max_size = 16GB
/etc/php/7.3/cli/php.ini:post_max_size = 16GB
/etc/php/7.3/phpdbg/php.ini:post_max_size = 8M

root@cloud:~# grep -R "memory_limit" /etc/php/
/etc/php/7.3/fpm/pool.d/www.conf:;php_admin_value[memory_limit] = 32M
/etc/php/7.3/fpm/php.ini:memory_limit = 512M
/etc/php/7.3/cli/php.ini:memory_limit = 512M
/etc/php/7.3/phpdbg/php.ini:memory_limit = 128M

我找不到问题。也许你们可以帮助我。

【问题讨论】:

【参考方案1】:

好的,这是 php.ini 文件中的错误配置。 我完全删除了 nextcloud 容器中的 PHP,重新安装它现在可以工作了。

【讨论】:

以上是关于lxc 与 nextcloud 和 nginx 代理:未知:POST Content-Length的主要内容,如果未能解决你的问题,请参考以下文章

Nextcloud 安装与优化 centos7 php7 nginx MariaDB

Nginx 代理管理器坏网关(Docker Wordpress 和 Nextcloud)

利用docker和docker-compose部署Nextcloud服务(nginx-fdm-postgres)

Docker使用nginx-proxy对Nextcloud进行https反向代理

如何在 CentOS 7 中使用 Nginx 和 PHP7-FPM 安装 Nextcloud

nextcloud 的 Nginx 反向代理不起作用