Nginx and owncloud in a subfolder

I want to have an owncloud instance in a subfolder on my nginx server. But I have problems with some files requested by opwncloud (it seems css and js are not loading).

Here is the nginx config for this virtual host:

server {
   listen         80;
   server_name    blackblock.22decembre.eu;
   return 301     https://blackblock.22decembre.eu$request_uri;
}

server {
listen 443 default_server ssl;

server_name blackblock.22decembre.eu;
root /srv/www/blackblock/;

access_log  /var/log/nginx/blackblock.access.log;
error_log   /var/log/nginx/blackblock.errors.log;

index index.html index.php;

# This block will catch static file requests, such as images, css, js
# The : prefix is a "non-capturing" mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(:ico|css|js|gif|jpeg|png)$ {
    # Some basic cache-control for static files to be sent to the browser
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# remove the robots line if you want to use wordpress" virtual robots.txt
# location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }

#location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
location ~ \.php {
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_index index.php;
    fastcgi_pass unix:/run/php5-fpm.sock;
    include fastcgi_params;
}

location /roundcube/program/js/tiny_mce/ { alias /usr/share/tinymce/www/; }
location /roundcube/(config|temp|logs) { deny all;}

 ##### owncloud
 location ~ /owncloud/ {
root /srv/www/blackblock/owncloud/;
try_files $uri $uri/ index.php;

#client_max_body_size 10G; # 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 ~ ^/remote.php(/.*)$ {
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_pass unix:/run/php5-fpm.sock;
    include fastcgi_params;
    }

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

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

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

    # Optional: set long EXPIRES header on static assets
    #location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
     #       expires 30d;
            # Optional: Don't log access to assets
      #      access_log off;
#   }
}

    ##### torrent (not related to owncloud, flask application)
location = /flask-torrent { rewrite ^ /flask-torrent/ last; }

 }

I can not find why owncloud is not loading correctly! You can take a look at the site, I feel good and am provided for this: https://blackblock.22decembre.eu/owncloud/ (cacert certificate). If I run a specific virtual host for owncloud, it works fine, but I do not want it, I prefer it in a subfolder of this host (blackblock)!

+3
source share
4 answers

, : http://www.aelog.org/install-owncloud-in-a-subdirectory-using-nginx/

:

server {
    listen 80;
    server_name example.com;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
    ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;

    # Add headers to serve security related headers
    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;

    # Path to the root of your website (one level above owncloud folder)
    root /var/www;
    # set max upload size
    client_max_body_size 10G;
    fastcgi_buffers 64 4K;

    # Disable gzip to avoid the removal of the ETag header
    gzip off;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    # ownCloud blacklist
    location ~ ^/owncloud/(?:\.htaccess|data|config|db_structure\.xml|README) {
        deny all;
        error_page 403 = /owncloud/core/templates/403.php;
    }

    index index.php;

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

    location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README){
        deny all;
    }

    location /owncloud {
        error_page 403 = /owncloud/core/templates/403.php;
        error_page 404 = /owncloud/core/templates/404.php;

        rewrite ^/owncloud/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/owncloud/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/owncloud/webdav(.*)$ /remote.php/webdav$1 redirect;

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

        # The following rules are only needed with webfinger
        rewrite ^/owncloud/.well-known/host-meta /public.php?service=host-meta last;
        rewrite ^/owncloud/.well-known/host-meta.json /public.php?service=host-meta-json last;
        rewrite ^/owncloud/.well-known/carddav /remote.php/carddav/ redirect;
        rewrite ^/owncloud/.well-known/caldav /remote.php/caldav/ redirect;

        try_files $uri $uri/ index.php;
    }

    location ~ \.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 HTTPS on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location / {
         root /var/www/html/;
         index index.html;
    }

    # Optional: set long EXPIRES header on static assets
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        # Optional: Don't log access to assets
        access_log off;
    }
}

: https://github.com/owncloud/documentation/pull/1704

+3

, ownCloud nginx, , nginx SCRIPT_NAME. ownCloud domain.tld/owncloud/index.php, , $_SERVER['SCRIPT_NAME'] /owncloud/index.php, nginx ( include fastcgi_params;) index.php. , : fastcgi_param SCRIPT_NAME /owncloud/$fastcgi_script_name; php-location-block nginx.

nginx. , ; , , . : nginx 1.2.1 php 5.4.4 64- Debian Wheezy.

    location /owncloud/ {
            alias /var/www/owncloud/;
            location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
                    deny all;
            }
            rewrite ^/owncloud/caldav(.*)$ /owncloud/remote.php/caldav$1 redirect;
            rewrite ^/owncloud/carddav(.*)$ /owncloud/remote.php/carddav$1 redirect;
            rewrite ^/owncloud/webdav(.*)$ /owncloud/remote.php/webdav$1 redirect;
            rewrite ^/owncloud/.well-known/host-meta /owncloud/public.php?service=host-meta last;
            rewrite ^/owncloud/.well-known/host-meta.json /owncloud/public.php?service=host-meta-json last;

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

            rewrite ^/owncloud/apps/([^/]*)/(.*\.(css|php))$ /owncloud/index.php?app=$1&getfile=$2 last;
            rewrite ^(/owncloud/core/doc/[^\/]+/)$ $1/index.html;

            try_files $uri $uri/ index.php;

            location ~ ^/owncloud/(.+?\.php)/? {  # note the question mark here and in the next line!
                    fastcgi_split_path_info ^/owncloud/(.+?\.php)(/?.*)$;
                    set $path_info $fastcgi_path_info;  # workaround for bug: try_files resets fastcgi_path_info for some reason.
                    try_files $fastcgi_script_name = 404;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_param PATH_INFO $path_info;
                    fastcgi_param HTTPS on;
                    fastcgi_param SCRIPT_NAME /owncloud/$fastcgi_script_name;  # !!!
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
            }
    }
+2

, , , Nginx, . ( ) , Nginx Cloud ownCloud.

PHP Nginx:

Nginx PHP5-FPM, Nginx:

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

Nginx:

:

location /owncloud {
   rewrite ^ https://$http_host$request_uri? permanent;
   }

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

PHP5-FPM:

, PHP5-FPM ( - /etc/php 5/fpm/pool.d/www.conf Ubuntu) , TCP, . PHP5-FPM .

:

listen = /var/run/php5-fpm.sock

( ):

;listen = 127.0.0.1:9000

, , OwnCloud Nginx.

http://doc.owncloud.org/server/5.0/admin_manual/installation/installation_others.html

0

, / /index.php, , index - URI .

location ~ /owncloud/ location ^~ /owncloud

, , owncloud, , , , , $uri /owncloud /file.ext , ,

rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;

- ,

  • ^/caldav(.*)$ , uri ^/owncloud
  • /remote.php/...

:

rewrite ^/owncloud/caldav(.*)$ /owncloud/remote.php/caldav$1 redirect;

, .

0

All Articles