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 #22

Closed
wants to merge 3 commits into from
Closed

oc-1875 : running OwnCloud on an alias (or not) with Nginx #22

wants to merge 3 commits into from

Conversation

illwieckz
Copy link

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["SCRIPT_NAME"], $_SERVER["DOCUMENT_URI"] and $_SERVER["PATH_INFO"].

I was invited to do a "merge request":
http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-1875#comment_1_1877_9612
I hope to do it right!

@karlitschek
Copy link
Contributor

Hi Thomas. Thanks for the patch. unfortunately we are in feature freeze and 4.5 is only a few days away. We will test and merge this after 4.5

@illwieckz
Copy link
Author

OK, not a problem, it gives me more time for further testing and and explore various use cases, for exemple I will try OC use on a sub directory, this is a case where $SERVERROOT != $DOCUMENTROOT :)

@bartv2
Copy link
Contributor

bartv2 commented Oct 10, 2012

apache doesn't fill $_SERVER["DOCUMENT_URI"], so this can't be used as is.

@illwieckz
Copy link
Author

I made ​​some tests and you're right, this variable is empty ... :/
However, it seems that some apache modules set this variable (like http://httpd.apache.org/docs/current/mod/mod_include.html#includevars ) , but it's not the case of mod_php.

Also, tests show me another problem with apache :
when requesting /alias/script.php when /alias is an alias, apache set $_SERVER["SCRIPT_NAME"] to /alias/script.php instead of /script.php, including WEBROOT into SCRIPT_NAME, which is not a good idea…

I'm working to find another way to guess WEBROOT (there is other variables).

@illwieckz
Copy link
Author

OK, if nginx mimic apache (fastcgi_param SCRIPT_NAME /alias$fastcgi_script_name;)
I can do this to guess WEBROOT :

$PATH_ARRAY=explode('/', $_SERVER['SCRIPT_NAME']);
$REAL_SCRIPT_NAME='/'.end($PATH_ARRAY);
$WEBROOT=substr($_SERVER["SCRIPT_NAME"], 0, 0 - strlen($REAL_SCRIPT_NAME));

This works for both Apache and Nginx, for three use case :
example.com/script.php
example.com/sudbir/script.php
example.com/alias/script.php

if we do not trust $_SERVER['SCRIPT_NAME'], we can guess it from $_SERVER['REQUEST_URI'] without "?$_SERVER['QUERY_STRING']" or from $_SERVER['REQUEST_URI'] without $_SERVER['PATH_INFO'].


with /var/www/script.php and /var/www/subdir/script.php containing

with apache (localhost) and nginx (localhost:8080) configured with alias /alias and without alias, I get this :

GET http://localhost/script.php
$WEBROOT :
GET http://localhost/script.php?query
$WEBROOT :
GET http://localhost/script.php/pathinfo
$WEBROOT :
GET http://localhost/subdir/script.php
$WEBROOT : /subdir
GET http://localhost/subdir/script.php?query
$WEBROOT : /subdir
GET http://localhost/subdir/script.php/pathinfo
$WEBROOT : /subdir
GET http://localhost/alias/script.php
$WEBROOT : /alias
GET http://localhost/alias/script.php?query
$WEBROOT : /alias
GET http://localhost/alias/script.php/pathinfo
$WEBROOT : /alias
GET http://localhost/alias/subdir/script.php
$WEBROOT : /alias/subdir
GET http://localhost/alias/subdir/script.php?query
$WEBROOT : /alias/subdir
GET http://localhost/alias/sudbir/script.php/pathinfo
GET http://localhost:8080/script.php
$WEBROOT :
GET http://localhost:8080/script.php?query
$WEBROOT :
GET http://localhost:8080/script.php/pathinfo
$WEBROOT :
GET http://localhost:8080/subdir/script.php
$WEBROOT : /subdir
GET http://localhost:8080/subdir/script.php?query
$WEBROOT : /subdir
GET http://localhost:8080/subdir/script.php/pathinfo
$WEBROOT : /subdir
GET http://localhost:8080/alias/script.php
$WEBROOT : /alias
GET http://localhost:8080/alias/script.php?query
$WEBROOT : /alias
GET http://localhost:8080/alias/script.php/pathinfo
$WEBROOT : /alias
GET http://localhost:8080/alias/subdir/script.php
$WEBROOT : /alias/subdir
GET http://localhost:8080/alias/subdir/script.php?query
$WEBROOT : /alias/subdir
GET http://localhost:8080/alias/sudbir/script.php/pathinfo

[EDIT: HUM, it does'nt works for scripts like /settings/personnal.php, I continue to dig…]

@illwieckz
Copy link
Author

With this commit, it should works on both Apache and Nginx (if Nginx mimics Apache naming) for these installations :

  • domain configuration
    with request GET example.org/
    with DocumentRoot in /var/www
    with owncloud installed /var/www
  • subdirectory under a domain configuration
    with request GET example.org/owncloud
    with DocumentRoot in /var/www
    with owncloud installed in /var/www/owncloud
  • alias configuration
    with request GET example.org/alias
    with DocumentRoot in /var/www
    with owncloud installed in /var/www
  • subdirectory under an alias configuration
    with request GET example.org/alias/owncloud
    with DocumentRoot in /var/www
    with owncloud installed in /var/www/owncloud

WEBROOT and SUBURI are calculated without DocumentUri, from OC::SERVERROOT, $_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'] and $_SERVER['PATH_INFO']

Note : to be more agnostic, we can calculate $_SERVER['SCRIPT_NAME'] from $_SERVER['REQUEST_URI'] without "?$_SERVER['QUERY_STRING']" or from $_SERVER['REQUEST_URI'] without $_SERVER['PATH_INFO']

@DeepDiver1975
Copy link
Member

Can you please rebase? Automatic merge not possible at the moment. - THX

Who wants to take care of this? I have no idea about Nginx.

@illwieckz
Copy link
Author

I'll do some more tests, it is necessary that I check another case that I have not yet tested

Who wants to take care of this? I have no idea about Nginx.

This is especially a problem with fastcgi or anything that is not Apache mod_php :D

Also, I have a question: do you think it is a good idea to set webroot in config.php: the idea is to use this variable if the administrator has set it, and calculate if it is not filled (with overload due to comparison of strings). Also, this would allow advanced administrators to have OC working with exotic sofware when calculation of this variable will not work.

@DeepDiver1975
Copy link
Member

@illwieckz please rebase - I'll try to find reviewers for this - THX

@illwieckz
Copy link
Author

I've found a bug with this code : it doesn't works when ownCloud is accessed via an alias AND is not installed, the installation page never comes because redirecting indefinitely :

illwieckz@arwen tmp $ wget --no-check-certificate https://owncloud.example.org/owncloud 2>&1 | grep '301\|302' -A1 | head -n 17
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://owncloud.example.org/owncloud/ [following]
--
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://owncloud.example.org/owncloud/index.php [following]
--
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://owncloud.example.org/owncloud/index.php [following]
--
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://owncloud.example.org/owncloud/index.php [following]
--
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://owncloud.example.org/owncloud/index.php [following]
--
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://owncloud.example.org/owncloud/index.php [following]

So,
If ownCloud is not installed and requested with a alias, it doesn't works.
If ownCloud is already installed and requested with an alias, it works.
If ownCloud is not installed and requested with a domain name, it works.
If ownCloud is installed and requested with a domain name, it works.

I don't know why. The bug is perhaps elsewhere in ownCloud code, my code only handle URL writing, not redirection.

@illwieckz
Copy link
Author

@DeepDiver1975 : how I rebase on github ?

@DeepDiver1975
Copy link
Member

@tanghus
Copy link
Contributor

tanghus commented Nov 12, 2012

@illwieckz Can you make this PR uptodate by following @DeepDiver1975 s instructions or can you resubmit? Thanks for the link btw @DeepDiver1975 ;)

@illwieckz
Copy link
Author

@DeepDiver1975 : thanks your page was more relevant than this one : http://learn.github.com/p/rebasing.html

But the merge was too complicated so I thought it might be easier to fork the repo again and to put my changes into a single commit to resubmit... bad idea, GitHub replied "404" when I try to fork again. :/

@illwieckz
Copy link
Author

You'll probably like this one : #385
The current Pull Request (#22) can be forgotten.

@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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants