3

我想在我的 nginx 服务器的子文件夹中有一个 owncloud 实例。但是我对 opwncloud 请求的一些文件有问题(似乎 css 和 js 没有加载)。

这是此虚拟主机的 nginx conf 文件:

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

 }

我找不到 owncloud 无法正确加载的原因!您可以查看该网站,我对此感觉很好并且很安全:https ://blackblock.22decembre.eu/owncloud/(cacert 证书)。如果我为owncloud启动一个特定的虚拟主机,它可以完美运行,但我不想要,我更喜欢它在这个主机的子文件夹中(blackblock)!

4

4 回答 4

3

其他答案都不适合我,我终于从这个博客中得到了一个可行的解决方案: 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

于 2015-09-26T20:13:58.123 回答
2

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;到 nginx conf 文件中的 php-location-block。

我的 nginx 配置文件的相关部分如下。请注意,我还没有完全测试过它;乍一看,它似乎工作。我的系统:Debian Wheezy 64 位上的 nginx 1.2.1 和 php 5.4.4。

    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;
            }
    }
于 2014-06-25T20:00:16.147 回答
0

首先让我指出/not working yet /index.phpis working,这意味着该index语句由于某种原因不起作用,或者您的 URI 与另一个块匹配。

为了安全location ~ /owncloud/重写location ^~ /owncloud

您的配置需要大量重写,请注意默认配置是为安装在根目录上的 owncloud 制作的,您的子目录中您需要修复一些事情,例如请记住,这$uri将包括/owncloud/file.ext跳出 owncloud 文件夹,所以所有重写就像

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

由于两件事需要修复,

  1. ^/caldav(.*)$永远不会发生,uri 将始终以^/owncloud
  2. /remote.php/...会在 owncloud 外面看

修复将是这样的:

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

试试这些,然后告诉我它是怎么回事。

于 2014-02-09T17:06:22.357 回答
0

抱歉,如果您已经查看过此内容,但是您发布的配置中缺少包括多个 Nginx 位置指令在内的一些项目。我建议您查看配置说明(本文底部的链接)并确保您拥有 ownCloud 和 ownCloud 数据的 Nginx 位置指令。

检查 Nginx PHP 处理程序:

你的 Nginx 配置应该包含 PHP5-FPM 的处理程序,将它放在 Nginx 配置顶部的 server 指令之前:

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 池配置(通常在 Ubuntu 上的 /etc/php5/fpm/pool.d/www.conf 之类的地方)设置为侦听套接字而不是与您的处理程序匹配的 TCP 端口。PHP5-FPM 套接字与端口的配置指令如下。

示例套接字:

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

示例端口(注释掉以匹配上游处理程序):

;listen = 127.0.0.1:9000

另外,如果您还没有这样做,请查看 Nginx 的 ownCloud 配置说明。

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

于 2014-02-08T19:26:58.303 回答