Skip to content

503 Error after nextcloud runs a time #237

Description

@benhartwich

Steps to reproduce

  1. Install nextcloud on Debian 8 with nginx and php5.6
  2. let it run a time
  3. change your pc and try to reach nextcloud in chrome => 503: Service not available.

Actual behaviour

When I restart php5-fpm I can access nextcloud at chrome again. I´ve tested it with Firefox also and the same problem. It seems to be that only index.php is affected. When I run other URLs I can access nextcloud.
My php-fpm conf:

[cloud]

listen = /var/run/php5-fpm-cloud.sock
listen.backlog = 65535
listen.allowed_clients = 127.0.0.1

user = cloud
group = cloud
listen.mode = 0660
listen.owner = cloud
listen.group = www-data

pm.process_idle_timeout = 10s
pm.max_requests = 0
pm = dynamic
pm.max_children = 15
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 7

chdir = /

php_admin_value[open_basedir] = /var/kunden/cloud:/usr/share/php5:/tmp:/var/tmp:/dev/urandom:
php_admin_value[disable_functions] = dl,passthru,shell_exec,system,proc_open,popen,show_source
php_admin_value[memory_limit] = 256M
php_admin_value[max_execution_time] = 240
php_admin_value[upload_max_filesize] = 750M
php_admin_value[post_max_size] = 750M
php_admin_value[max_input_time] = 3600
php_admin_value[max_execution_time] = 3600

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Server configuration

Operating system: Debian 8

Web server: nginx 1.11.1

Database: MariaDB

PHP version: 5.6.22

Nextcloud version: 9.0.5

Updated from an older Nextcloud/ownCloud or fresh install: new install

Where did you install Nextcloud from: nextcloud.com

Signing status (Nextcloud 9.0 and above):

Login as admin user into your Nextcloud and access 
http://example.com/index.php/settings/integrity/failed 
paste the results here.
 errors have been found.

List of activated apps:

If you have access to your command line run e.g.:
sudo -u www-data php occ app:list
from within your Nextcloud installation folder

The content of config/config.php:

If you have access to your command line run e.g.:
sudo -u www-data php occ config:list system
from within your Nextcloud installation folder

or 

Insert your config.php content here
(Without the database password, passwordsalt and secret)

Are you using external storage, if yes which one: local

Are you using encryption: no

Client configuration

Browser: Chrome

Operating system: Windows 7 64bit

Logs

Web server error log

no log

Nextcloud log (data/owncloud.log)

"PHP","message":"Comments starting with '#' are deprecated in Unknown on line 1 at Unknown#0","level":3,"time":"2016-06-27T19:15:20+00:00","method":"PROPFIND","url":"\/remote.php\/webdav\/",

Activity

  1. self-assigned this
    on Jun 27, 2016
  2. added this to the Nextcloud 9.0.52 milestone on Jun 27, 2016
  3. LukasReschke commented on Jun 27, 2016

    @LukasReschke
    Member

    That's the second report I get of this but I still wasn't able to reproduce this locally on my instances. Then again, I only do use Apache. For other NGINX users it works fine though.

    Is there any chance you can get me super easy reproduction steps (e.g. a docker container) or access to your machine using SSH (https://github.com/LukasReschke.keys)? That would make it way easier for me to debug this.

  4. aktavor69 commented on Jun 29, 2016

    @aktavor69

    Hi, its me again, we talking together few days ago

    Its pretty easy to reproduce.

    If you want, I reproduce my config on a VPS, I will send you credentials.

    edit : email sent

  5. removed this from the Nextcloud 9.0.52 milestone on Jun 30, 2016
  6. removed their assignment
    on Jun 30, 2016
  7. LukasReschke commented on Jun 30, 2016

    @LukasReschke
    Member

    This is caused by a NGINX setting, the following is documented at https://docs.nextcloud.org/server/9/admin_manual/installation/nginx_owncloud_9x.html:

    fastcgi_split_path_info ^(.+.php)(/.+)$;

    This will fail hard, if somebody accesses / directly without index.php in it then $_SERVER['SCRIPT_NAME'] is set to an empty string instead of index.php. This can lead to any kind of problems and the NGINX config should probably be addressed for that.

    For now I'd just recommend to remove that line from your config.

    @josh4trunks @mmattel Any idea how the NGINX config could be adjusted to keep this in mind?

  8. benhartwich commented on Jun 30, 2016

    @benhartwich
    Author

    I´ve commented this line out, but have the same error. the owncloud client has a detailled error message: Internal Server error: The Request URI /remote.php/webdav/ did not end with the contents of PATH_INFO(i)

  9. josh4trunks commented on Jun 30, 2016

    @josh4trunks
    Contributor

    @LukasReschke
    The line you reference doesn't affect "SCRIPT_NAME" passed to PHP, since that variable is set in fastcgi_params. But it does affect "SCRIPT_FILENAME"

    A request for "/" would be matched by the / block, it does not match the PHP block with the line you reference.
    It would then be rewritten to "/index.php" > then match the PHP block, which would set the "SCRIPT_FILENAME" to "/index.php"

  10. josh4trunks commented on Jun 30, 2016

    @josh4trunks
    Contributor

    @benhartwich if you comment out that line, alot of aspects of owncloud won't work.

    @LukasReschke I don't think you should tell people to remove that line =P

  11. LukasReschke commented on Jun 30, 2016

    @LukasReschke
    Member

    https://github.com/nextcloud/server/blob/stable9/lib/base.php#L518 calls IRequest::getScriptName(), this function reads $_SERVER['SCRIPT_NAME']. With the documented NGINX config SCRIPT_NAME is empty when opening / instead of /index.php. (just do a var_dump($_SERVER);exit(); in your index.php)

    Removing that line from the config sets the proper SCRIPT_NAME. I don't have much experience with NGINX but this seems just wrong. (expected behaviour would be to get "index.php")

  12. josh4trunks commented on Jun 30, 2016

    @josh4trunks
    Contributor

    @LukasReschke A request for "/" would not be passed to PHP. It would first be rewritten to "/index.php"

    Please see #237 (comment)

  13. LukasReschke commented on Jun 30, 2016

    @LukasReschke
    Member

    @josh4trunks To illustrate the problem, I have created a docker. It is based on the config from https://docs.nextcloud.org/server/9/admin_manual/installation/nginx_examples.html (which is basically a 1:1 copy of the ownCloud docs page)

    To test it please execute:

    git clone https://gist.github.com/069d68d341254e265a143a9a3385c52c.git issue-237
    cd issue-237/
    docker build -t nextcloud .
    docker run -t -i nextcloud /bin/bash
    

    Inside the container start PHP FPM and NGINX:

    /etc/init.d/nginx start && /etc/init.d/php5-fpm start
    

    Now cURL /index.php and / directly:

    root@63c097aa0c98:/# curl http://localhost/
    string(0) ""
    root@63c097aa0c98:/# curl http://localhost/index.php
    string(10) "/index.php"
    

    As you can see, the index.php is invoked in both but the proper SCRIPT_NAME is only set for the one where the index.php is appended. That's actually the problem that I'm pointing out here.

    From a software perspective we do expect to get a proper $_SERVER['SCRIPT_NAME'] for the / URL as well.

  14. josh4trunks commented on Jun 30, 2016

    @josh4trunks
    Contributor

    @LukasReschke Can you post/link to the exact nginx config and fastcgi_params so I can take a look.
    If it is exactly as the docs, "/" would be internally rewritten to "/index.php" and SCRIPT_NAME would be "/index.php".

    Can you also try replacing the index.php with this to confirm SCRIPT_NAME is being set incorrectly.

    <?php
    phpinfo();
    ?>
    

    I can test this as well tonight. Currently running ownCloud but if you are correct this issue would crop up before touching the PHP code.

    ####EDIT####
    Looking at your docker file, looks like you did what I'm thinking. Can you post your fastcgi_params

  15. 13 remaining items

  16. MorrisJobke commented on Jul 1, 2016

    @MorrisJobke
    Member

    @josh4trunks Could we add this to the documentation? Or is this something special to the environment?

  17. josh4trunks commented on Jul 1, 2016

    @josh4trunks
    Contributor

    We should make this change. In default environments this is needed since we rely on rewrite now. It only doesn't affect some if they have something like fastcgi_index set to index.php, while this is common, it is not default.

    Change is from...

    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    

    to...

    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    

    This needs to be applied to both
    https://docs.nextcloud.org/server/9/admin_manual/installation/nginx_owncloud_9x.html#nextcloud-in-the-webroot-of-nginx
    https://docs.nextcloud.org/server/9/admin_manual/installation/nginx_owncloud_9x.html#nextcloud-in-a-subdir-of-nginx

  18. added a commit that references this issue on Jul 1, 2016
  19. MorrisJobke commented on Jul 1, 2016

    @MorrisJobke
    Member

    @josh4trunks nextcloud/documentation#40 should do the trick then ;)

  20. aktavor69 commented on Jul 1, 2016

    @aktavor69

    @MorrisJobke Nop, its not right.

    You forgot to remove

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    and add instead

    fastcgi_split_path_info ^(.+\.php)(/.*)$;

  21. MorrisJobke commented on Jul 1, 2016

    @MorrisJobke
    Member

    @MorrisJobke Nop, its not right.

    @aktavor69 Thanks a lot. I didn't spot that :( I fixed it :)

  22. added a commit that references this issue on Jul 1, 2016
  23. MorrisJobke commented on Jul 22, 2016

    @MorrisJobke
    Member

    This should be fixed with the new Nginx config

  24. Ardakilic commented on Oct 11, 2016

    @Ardakilic

    I had the same issue after migrating from owncloud,

    Simply switching the order of these two like this, as described above, fixed the problem for me:

    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    

    I'm using Debian 8.6, PHP7.0, MariaDB, Nginx 1.10.1. All manual install.

  25. techc0de commented on Mar 1, 2017

    @techc0de

    Hi,

    I don't meant to re-open this thread, but the NC admin manual have incorrect order of those above two lines. The above solution is verified.
    FYI: this error only occur on Android devices that use NextCloud app.

    Please update the admin manual.

    Thanks.

  26. added a commit that references this issue on Mar 1, 2017
  27. MorrisJobke commented on Mar 1, 2017

    @MorrisJobke
    Member

    Hi,

    I don't meant to re-open this thread, but the NC admin manual have incorrect order of those above two lines. The above solution is verified.
    FYI: this error only occur on Android devices that use NextCloud app.

    Please update the admin manual.

    Our manual is also open source. 😉 Nevertheless I fixed it - see nextcloud/documentation#371

  28. added 2 commits that reference this issue on Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagePending check for reproducibility or if it fits our roadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions