2

I am trying to use nginx + php-fpm to serve Owncloud on my raspberry pi. I am using a custom installation path /mnt/usbstorage/Documents/owncloud, and I want to access to owncloud using the url http://myserver/owncloud/.

I have configured the locations, and I am able to access the index.php. However, CSS and JS files are not being loaded.

The nginx configuration is the following (I've ommited some parts, to keep it to a minimum):

upstream php-handler {                                                                                                                                                              
        server unix:/var/run/php5-fpm.sock;                                                                                                                                         
}                                                                                                                                                                                   

server {                                                                                                                                                                            
        listen 80;                                                                                                                                                                  
        server_name _;

        location ^~ /owncloud {                                                                                                                                                     
            alias /mnt/usbstorage/Documents;                                                                                                                                    
            client_max_body_size 10G;                                                                                                                                           
            fastcgi_buffers 64 4K;                                                                                                                                              
            gzip off;                                                                                                                                                           

            index /owncloud/index.php;                                                                                                                                          
            error_page 403 /owncloud/core/templates/403.php;                                                                                                                    
            error_page 404 /owncloud/core/templates/404.php;                                                                                                                    

            location /owncloud {                                                                                                                                                
                    rewrite ^ /owncloud/index.php$uri;                                                                                                                          
            }                                                                                                                                                                   

           location ~ ^/owncloud/(?:index|remote|public|cron|core|ajax|update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {                 
                    fastcgi_split_path_info ^(.+\.php)(/.*)$;                                                                                                                   
                    include fastcgi_params;                                                                                                                                     
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                                                                                           
                    fastcgi_param PATH_INFO $fastcgi_path_info;                                                                                                                 
                    fastcgi_param modHeadersAvailable true;                                                                                                                     
                    fastcgi_param front_controller_active true;                                                                                                                 
                    fastcgi_pass php-handler;                                                                                                                                   
                    fastcgi_intercept_errors on;                                                                                                                                
            }                                                                                                                                                                   

            location ~* \.(?:css|js)$ {                                                                                                                                                          
                    try_files $uri /owncloud/index.php$uri$is_args$args;                                                                                                     
                    access_log off;                                                                                                                                             
            }                                                                                                                                                                   

            location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {                                                                                                         
                    try_files $uri /owncloud/index.php$uri$is_args$args;                                                                                                        
                    access_log off;                                                                                                                                             
            }                                                                                                                                                                   
        }                                                                                                                                                                           
}                                              

From the Nginx logs when I try to access, for example, a CSS file, I can see that the correct location block is being used, and even that the $uri is also correct. However, when trying to fetch the file, Nginx uses a different path (see line with http filename):

2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: "/owncloud"                                                                       
2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: ~ "^/owncloud/(?:build|tests|config|lib|3rdparty|templates|data)/"
2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: ~ "^/owncloud/(?:\.|autotest|occ|issue|indie|db_|console)"   
2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: ~ "^/owncloud/(?:index|remote|public|cron|core|ajax|update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[3
2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: ~ "^/owncloud/(?:updater|ocs-provider)(?:$|/)"                                                                      
2016/09/16 22:31:59 [debug] 31460#0: *2274 test location: ~ "^/owncloud(.*\.(?:css|js))$"                                                   
2016/09/16 22:31:59 [debug] 31460#0: *2274 using configuration "^/owncloud(.*\.(?:css|js))$"                                
2016/09/16 22:31:59 [debug] 31460#0: *2274 http script capture: "/core/css/styles.css"                                 
2016/09/16 22:31:59 [debug] 31460#0: *2274 trying to use file: "/core/css/styles.css" "/mnt/usbstorage/Documents/core/css/styles.css"                                               
2016/09/16 22:31:59 [debug] 31460#0: *2274 http script var: "/owncloud/core/css/styles.css"                                 
2016/09/16 22:31:59 [debug] 31460#0: *2274 trying to use file: "/owncloud/core/css/styles.css" "/mnt/usbstorage/Documents/owncloud/core/css/styles.css"
2016/09/16 22:31:59 [debug] 31460#0: *2274 try file uri: "/owncloud/core/css/styles.css"                                                                                            
2016/09/16 22:31:59 [debug] 31460#0: *2274 http filename: "/mnt/usbstorage/Documents/core/css/styles.css"                                                                           
2016/09/16 22:31:59 [error] 31460#0: *2274 open() "/mnt/usbstorage/Documents/core/css/styles.css" failed (2: No such file or directory), client: 192.168.1.29, server: _, request: "
2016/09/16 22:31:59 [debug] 31460#0: *2274 http finalize request: 404, "/owncloud/core/css/styles.css?" a:1, c:1
2016/09/16 22:31:59 [debug] 31460#0: *2274 http special response: 404, "/owncloud/core/css/styles.css?"
2016/09/16 22:31:59 [debug] 31460#0: *2274 internal redirect: "/owncloud/core/templates/404.php?"  

Any ideas why nginx is using this other path without owncloud/ in it?

joacomug
  • 21
  • 2
  • Try `root /mnt/usbstorage/Documents;`. The `alias` directive is intended to remove the `owncloud` from the URI. See [this document](http://nginx.org/en/docs/http/ngx_http_core_module.html#alias) for details. – Richard Smith Sep 17 '16 at 13:46
  • You mean inside the `location` block? Because I had read somewhere that inside location it should be `alias` that is used. I didn't want to put `root` ouside the location block because I have other apps that I'm serving with nginx. – joacomug Sep 17 '16 at 14:15
  • Well. It worked, thanks. However, I still don't understand why the use of `root` inside `location` block is discouraged (see [Pitfalls and Common Mistakes](https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/)) – joacomug Sep 17 '16 at 14:34
  • Read it again. It means don't specify the same `root` multiple times, when once will do. `alias` has a specific function which is different from `root` (see the link in my first comment). – Richard Smith Sep 17 '16 at 14:41

0 Answers0