Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oc-1875 : running OwnCloud on an alias (or not) with Nginx [the real one] #385

Closed
wants to merge 7 commits into from

Conversation

illwieckz
Copy link

This Pull Request is a similar to #22 (the #22 could be deleted).
This is another attempt to do things properly.
I hope this Pull Request is clean and done properly :

  • 1 commit
  • dedicated branch
  • rebased and up to date with owncloud/core

For my first "Pull Request" attempt I wrote something like this :

Hi, this is the code that I described in my recent bug report:
http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-1875

Purpose is to use Owncloud as an alias with Nginx¹. The code calculate OC::$SUBURI and OC::$WEBROOT using $_SERVER

¹ Nginx or other HTTPd server

@ghost
Copy link

ghost commented Nov 13, 2012

Can one of the admins verify this patch?

@DeepDiver1975
Copy link
Member

This is ok to test

@DeepDiver1975
Copy link
Member

Unit Tests are no longer executed.
Can you please have a look?
Thx

@karlitschek
Copy link
Contributor

Thanks again for the patch. Can you document your code a bit more so that it is easier to understand what you want to do here? Also the -13 smells as you rely on having ownCloud installed in a specific folder or a specific host. You shouldn´t do that. The Url is completely flexible.

@illwieckz
Copy link
Author

Hum sorry,
I did not write that line. This was the original code that I modified:

OC::$SERVERROOT=str_replace("\\", '/', substr(__FILE__, 0, -13));

is similar to

OC::$SERVERROOT=str_replace("\\", '/', substr(__FILE__, 0, strlen('/lib/base.php')));

But I did a mistake when applying my patch, I replace new code (based on DIR path, written by another than me) by old code (based on FILE path, written by another than me) :

OC::$SERVERROOT=str_replace("\\", '/', substr(__DIR__, 0, -4));

which is similar to

OC::$SERVERROOT=str_replace("\\", '/', substr(__DIR__, 0, strlen('/lib')));

Perhaps we need to revert this line. That was not my idea, the previous code does this, this is the only part I don't modified.

@karlitschek : __FILE__ path is not related to URL, in fact it's the only path which does'nt change and this is the only reliable information we have, because it is not apache or nginx which provides it, but php (and there is no alias inside the filesystem ^^), it's the file path of the script (and the last characters '/lib/base.php' is well known)

@@ -119,25 +119,26 @@ public static function autoload($className) {

public static function initPaths() {
// calculate the root directories
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagine your httpd document root is '/var/www'
→ requesting /index.html serves /var/www/index.html
imagine you have an alias named 'alias'
→ requesting /alias/index.html serves /var/www/index.html
imagine you put owncloud on a subdir named 'dir'
→ requesting /alias/dir/index.html serves /var/www/dir/index.html

@karlitschek
Copy link
Contributor

Sorry. I don´t want annoy you but I meant documentation of the code of course. Not only in the pull request.

@illwieckz
Copy link
Author

I do not use my computer right now, I will comment the code later. Have you seen my comments I made ​​on GitHub?
https://github.com/owncloud/core/pull/385/files
I can copy these comments in the php source if you think they are good and understandable.

@karlitschek
Copy link
Contributor

Yes. I think this is understandable. Thanks a lot.

@karlitschek
Copy link
Contributor

I tested it and it works in all the scenarios that I have here. This is fragile code and it is possible that this doesn´t work in other, more esoteric environments. But this is something that we see when the code is in master. So a +1 from me for now if you add the documentation. Thanks a lot :-)

+1

@DeepDiver1975
Copy link
Member

@illwieckz
You'll get my okay as soon as the test suite is executing again - I'll have a look at it tonight as well. THX

@illwieckz
Copy link
Author

There is a use case I've not tested, it's reverse proxying like in #250, when user request 'GET /alias/index.php' to the reverse proxy, but owncloud receive 'GET /index.php'. I do not know what happens in this case.

@karlitschek :
yes it's fragile, what do you think about putting "WEBROOT" as optional value in config.php ?
for esoteric environments (like esoteric reverse proxy in front of esoteric httpd server ^^) it could be a good way to have OC functionnal if this code is'nt sufficient to handle all use cases ! no ?

@DeepDiver1975 :
It's a good idea to test with OwnCloud installed and not Installed, because before configuration, behavior may differ.

@ALL :
Where can I publish some Nginx configuration sample compatible with this code ? This one : http://owncloud.org/support/webserver-notes/ is not fully-functionnal and contains some errors.


Edit : I wrote this code to have it functionnal with apache without changing habits of apache users, other httpd servers should perhaps emulate the behavior of apache, I can say how to do it with Nginx and fastcgi.

@karlitschek
Copy link
Contributor

@illwieckz Yes. I think it is useful to make it possible to define the webroot, host, port and protocol in config.php for the cases that the automatic detection fails. Please also see this pull request #208 from @herbrechtsmeier Perhaps we can merge this somehow.

@JFOC
Copy link

JFOC commented Nov 13, 2012

imho defining the webroot would be great for general web server and do not need to make some custom configuration only for url

@illwieckz
Copy link
Author

I'll try to write "defining webroot in config.php" in another branch, and if it works I'll do another pull request.

@DeepDiver1975
Copy link
Member

The test are failing because $_SERVER["SCRIPT_NAME"] is set to '/usr/bin/phpunit' and as a result OC::$WEBROOT is '/usr/bin/phpunit' as well.

I think in the old code following lines implicitly caught this situation:
illwieckz@03fd34b#L0L125

@illwieckz Can you please take care of this? THX

@DeepDiver1975
Copy link
Member

@illwieckz ping ;-) THX

@illwieckz
Copy link
Author

sorry, it's hard to keep up (because job IRL ^^)

$_SERVER["SCRIPT_NAME"] is set to '/usr/bin/phpunit'

$_SERVER["SCRIPT_NAME"] must contain a path to a .php script, not the name of a binary (interpreter ?).
It seems to be a bug in phpunit.

Because phpunit is a tool used to debug, I think it's a very bad idea to write code to workaround phpunit bugs, it's like bypassing a debugger, who do this ?

Example with a correct interpreter :

illwieckz@arwen ~ $ echo '<?php echo $_SERVER["SCRIPT_NAME"]; ?>' > ~/script.php 
illwieckz@arwen ~ $ php ~/script.php 
/home/illwieckz/script.php

I think in the old code following lines implicitly caught this situation

It can't, this code works only if $_SERVER["SCRIPT_NAME"] end with a '/' character, but '/usr/bin/phpunit' end with a 't' character.

Also, '/usr/bin/phpunit/index.php' can't be a good $_SERVER["SCRIPT_NAME"], it must be something like '/var/www/index.php' (it depends of your configuration).

The code you pointed ensures $_SERVER["SCRIPT_NAME"] contains the 'index.php' script name if we request '/' with a http server configured to serve "index.php" as Index, and if the http server is buggy or misconfigurated and fill $_SERVER["SCRIPT_NAME"] with dirname instead of scriptname.

@DeepDiver1975
Copy link
Member

I did a quick search on this topic - for me it looks like setting $_SERVER["SCRIPT_NAME"] to phpunit is done on purpose. We should set $_SERVER["SCRIPT_NAME"] within out bootstrap code to the correct value (tests/bootstrap.php).

@icewind1991 Any objections? THX
@illwieckz Can you please give that a try? THX

@DeepDiver1975
Copy link
Member

@illwieckz rebase please and I'll try to get phpunit up and running
@karlitschek we still need/want this - or are the config parameters the answer to all issues concerning webroot detection ..... THX

@illwieckz
Copy link
Author

We should set $_SERVER["SCRIPT_NAME"] within out bootstrap code to the correct value

Yes I think phpunit must set $_SERVER variable before running the php script, and it must test several values.

we still need/want this - or are the config parameters the answer to all issues concerning webroot detection

The config parameters are a good answer, at least to be able to use owncloud without patching the code when using it on an exotic setup which breaks autodetection.

I'll rebase tonight

@illwieckz
Copy link
Author

Sorry for not being able to do it sooner! I just rebase.

@DeepDiver1975
Copy link
Member

@owncloud-bot retest this please

@illwieckz
Copy link
Author

Four things :

  • I rebased to have this pull request up to date with upstream code
  • I corrected a bug which appears when DOCUMENT_ROOT have a symlink in its path
  • I rewrote some little things to have this code following coding style guidelines
  • I wrote the previous comments inside the code, as requested here by @karlitschek

@illwieckz
Copy link
Author

in fact, five things :

  • Another guy has modified one line upstream after I forked, this code was modified to uses his line (which give the same result)

@karlitschek
Copy link
Contributor

Hi @illwieckz

Can you check if this can be fixed with the new config options, overwritehost, overwriteprotocol, overwritewebroot, overwritecondaddr ?

Thanks
Frank

@illwieckz
Copy link
Author

I will look at it, yes!

@karlitschek
Copy link
Contributor

@illwieckz Any news here? :-)

@ewildgoose
Copy link

I think the root problem here is that there are so many potential entry points into the code, ie it's acceptable to reference random .php scripts all around the filesystem?

I concede less experience with PHP, but were I writing this in perl/ruby I would have a single entry point into the code, which in turn talks to a "url router" and that would then have the job to map urls forward/backward to controller actions. So the only tiddle-able that I would need is the base-uri and everything else falls out from that

It seems that perhaps we can get there really easily though:

  • Map any bare paths to remote.php
  • map /public/ to public.php
  • make the base uri configurable

Now we get nice looking urls and most of the guesswork disappears from the code?

@bartv2
Copy link
Contributor

bartv2 commented Jul 5, 2013

please reopen if this is not fixed with the new config options, overwritehost, overwriteprotocol, overwritewebroot, overwritecondaddr

@bartv2 bartv2 closed this Jul 5, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Aug 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants