Owncloud with an Alias on Nginx

I have a Problem with our Nginx configuration, We have WordPress in our current root directory and i would like to setup owncloud on /owncloud by using a directory outside of our root. I have tried to setup an alias in nginx but i get an “access denied” from nginx or php i’am not sure.
My nginx config:

server {
    listen   134.34.60.101:80; ## listen for ipv4; this line is default and implied
    # listen   [::]:80 default ipv6only=on; ## listen for ipv6
    listen   134.34.60.101:443 default ssl;
    server_name fachschaft.inf.uni-konstanz.de www.fachschaft.inf.uni-konstanz.de;
    #root /usr/share/nginx/www;
    root /srv/www/website/current;
    index index.php;
    # reroute to old svn for now - Sammy 2013-11-26
    rewrite ^/svn/fachschaft(/.*)$ https://134.34.58.21/svn/fachschaft$1;

    ssl_certificate     ssl/chained-nginx.crt;
    ssl_certificate_key ssl/key-no-pw.pem;
    ssl_session_timeout 5m;
    ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;        
    ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;   
    if ($ssl_protocol = "") {
        rewrite ^ https://www.fachschaft.inf.uni-konstanz.de$request_uri? redirect;
    }
       #Owncloudsettings:
       client_max_body_size 256M; # set max upload size
       fastcgi_buffers 64 4K;
       rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
       rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
       rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;       


    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }


    location / {
        try_files $uri $uri/ /index.php?$args;

    }
    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }
    location ~ /adminier {
        # TODO find a better solution...
        alias /srv/www/adminier/index.php;
        fastcgi_split_path_info ^(.+.php)(/.+)$;

                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
    }

        location /owncloud {
        alias /srv/www/owncloud;

        try_files $uri $uri/ /index.php?$args;
#       fastcgi_split_path_info ^(/owncloud/.+.php)(/.+)$;
        fastcgi_split_path_info ^/owncloud/(.+.php)(/.+)$;

                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

            #Owncloud:
            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;

location ~ ^/owncloud/(data|config|.ht|db_structure.xml|README) {
              deny all;
}

    }



    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}

    # Roots WordPress Theme Rewrites
    # See http://roots.io/roots-101/
    location ~ ^/assets/(img|js|css|fonts)/(.*)$ {
    try_files $uri $uri/ /content/themes/fsinf-v2/assets/$1/$2;
    }
    location ~ ^/plugins/(.*)$ {
        try_files $uri $uri/ /content/plugins/$1;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
        #fastcgi_split_path_info ^(.+.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_index index.php;
        include fastcgi_params;
    #}

        location ~ ^(.+?.php)(/.*)?$ {
            try_files $1 = 404;

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$1;
            fastcgi_param PATH_INFO $2;
            fastcgi_param htaccessWorking true;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
#   location ~ /.ht {
#       deny all;

#}

location ~ ^/owncloud/(data|config|.ht|db_structure.xml|README) {
              deny all;
}
}

Has anyone an idea how it will work?

Related posts

Leave a Reply

1 comment

  1. 1) First of all, check

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

    I think You must use (.+?.php) here, ? will allow to correctly operate with *.php file as user data (I see You use it above). BTW, create info.php with

    <?php
    phpinfo();
    ?>
    

    Upload it to You server and try download it from owncloud/remote.php/webdav/SOME_FOLDER/info.php, its must start downloading, not executing.

    2) Make sure that fastcgi parameter PATH_INFO set correctly (using that info.php file), if not, try use

    set           $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO  $path_info;
    

    Don’t ask me why it’s set in such odd way, there was a bug, I don’t remember where I found this solution…

    3) Why You are using fastcgi_split_path_info in location /owncloud? This location is not blocking further regex matches (use location ^~ … to avoid it), so php scripts won’t get there, it will be matched in location ~ ^(.+?.php)(/.*)?$ below, which, by the way, seems doesn’t have fastcgi_split_path_info.

    Can’t say more, sorry, I just using owncloud for my home PC

    PS) I recommend You use include directive to split one huge config in multiple small configs to increase readability …