Use subdirectories instead of subdomains

Hello,
I am trying to use subdirectories instead of subdomains because my host
doesn’t support subdomains.

So, instead of having :

I would like to have :

I tried to do such things with location rules and alias.Example :

root /var/www/mysite;
location /owncloud {
    alias /var/www/mysite/owncloud;
    include /etc/nginx/conf.d/owncloud.conf;
    }

, but services like owncloud need location rules too, so I finally
have “location /example is outside location” errors.

How can I configure nginx for this?

Regards,

Why are you using an alias here? If the root is /var/www/mysite then

location /owncloud

would be interpreted as /var/www/mysite/owncloud which I’m guessing
is what you want.

Because the owncloud.conf contains location rules like this :

location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    location / {
            # The following 2 rules are only needed with webfinger
            rewrite ^/.well-known/host-meta 

/public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json
/public.php?service=host-meta-json last;

            rewrite ^/.well-known/carddav /remote.php/carddav/ 

redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/
redirect;

            rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

            try_files $uri $uri/ index.php;
    }

# deny direct access
location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
    deny all;
}

# enable php
    location ~ ^(.+?\.php)(/.*)?$ {
    try_files $1 = 404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$1;
    fastcgi_param PATH_INFO $2;
    fastcgi_param HTTPS on;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

}

Hello,

On 4/25/14, 12:06 PM, Thuban wrote:

Hello,
I am trying to use subdirectories instead of subdomains because my host
doesn’t support subdomains.

First suggestion is get a better host.

How can I configure nginx for this?

Why are you using an alias here? If the root is /var/www/mysite then

location /owncloud

would be interpreted as /var/www/mysite/owncloud which I’m guessing is
what you want.


Jim O.

“Never argue with a fool, onlookers may not be able to tell the
difference.” - Mark Twain

Thuban Wrote:

Hello,
I am trying to use subdirectories instead of subdomains because my
host
doesn’t support subdomains.

Posted at Nginx Forum:

Hello,

On 4/25/14, 1:17 PM, Thuban wrote:

         allow all;

 # enable php
     location ~ ^(.+?\.php)(/.*)?$ {
     try_files $1 = 404;
     include fastcgi_params;
     fastcgi_param SCRIPT_FILENAME $document_root$1;
     fastcgi_param PATH_INFO $2;
     fastcgi_param HTTPS on;
     fastcgi_pass unix:/var/run/php5-fpm.sock;

 }

I’m still not sure you’ve actually given a reason why you need an alias.

Those rules appear to be more or less a direct copy of the rules which
are at
Redirect Notice.
In my personal experience, they work perfectly well on ownCloud 6.
You’re almost certainly seeing “outside location” errors because of
issues with the root path or because of the way you have written the
included file.

I’d suggest following the exact instructions in the above link without
an included file and without an unnecessary alias.

If they don’t work, try rewriting them without nested locations. Use the
full path for each location. Read the docs at
Module ngx_http_core_module to
understand how locations are matched and this entire problem will be
much easier to understand.

If you can get them working without nested locations, you can nest some
if you want, but consider reading this thread about nested locations:
Nested Locations Better???.


Jim O.

“Never argue with a fool, onlookers may not be able to tell the
difference.” - Mark Twain

have “location /example is outside location” errors.
Because the owncloud.conf contains location rules like this :

    deny all;

}

I’m still not sure you’ve actually given a reason why you need an alias.

Infact, I don’t have a good reason for using alias, I just found this
proposal on the web while I was trying to configure this.

I also would like to use includes, because I might need to add other
services on the host and keeping things clean.

The idea is to define some subdirectories as is they were “new root”.

Sorry if my english isn’t clear…

Thank you for links, I will read.

Regards

Hello,

On 4/25/14, 3:59 PM, Thuban wrote:

Hello,

On 4/25/14, 1:17 PM, Thuban wrote:

[snip]

I’m still not sure you’ve actually given a reason why you need an alias.

Infact, I don’t have a good reason for using alias, I just found this
proposal on the web while I was trying to configure this.

Blindly following a “tutorial” without understanding what it does can be
a recipe for problems like this.

I also would like to use includes, because I might need to add other
services on the host and keeping things clean.

The idea is to define some subdirectories as is they were “new root”.

I agree that they provide for easy maintenance. However, in this case
you have errors are coming from the included file. That’s why I said to
try putting it all in your nginx.conf first until you get it working.
For me (and perhaps only me), I find it easier working with one file
when I’m trying to debug a configuration problem.

Sorry if my english isn’t clear…

Thank you for links, I will read.


Jim O.

“Never argue with a fool, onlookers may not be able to tell the
difference.” - Mark Twain

I managed to have something working by adding the complete path before
each location instructions like on this thread [1]

It would have been great to define a “new root” instead of full path
each times, but whatever.

Regards,

[1] : nginx + Owncloud in a subdirectory / Networking, Server, and Protection / Arch Linux Forums