将 Nginx 与 Nextcloud/Website/Paperwork 并行使用

Using Nginx with Nextcloud/Website/Paperwork parallel

我正在尝试 运行 Nextcloud、不同位置的主页和文书工作,但不知道如何正确配置我的 nginx-config。

我的工作树是这样的:

/var/www/
|-> website
|-> nextcloud
|-> paperwork

我的主页可以通过 web.domain.com 访问,我的 Nextcloud 可以通过 cloud.domain.com 访问。 现在我想让 Paperwork 在 web.domain.com/notes 下可用。 Paperwork 的 index.php 位于子文件夹 "paperwork/frontend/public".

这是我解决这个问题的尝试(没有整个 ssl 和云部分):

server{
    listen 443 ssl http2;
    server_name web.domain.com;
    error_log /var/log/nginx/debug.log debug;

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

    location /notes {
            alias /var/www/paperwork/frontend/public;
            index index.php index.html index.htm;
            try_files $uri $uri/index.php;
    }

    location ~ /(nextcloud|backups) {
            deny all;
            return 403;
    }
    location ^~ /nextcloud/ {
            deny all;
            return 402;
    }
    location ^~ /nextcloud/ {
            deny all;
            return 402;
    }

    location ~ \.php$ {
            try_files $uri =404;
            alias /var/www/paperwork/frontend/public;
            index index.php index.html index.htm;

            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME 
            $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
}

我尝试了很多不同的解决方案,但我得到了一个 404,因为他使用了错误的目录并且找不到 /var/www/notes/index.php(或类似的错误)或 nginx 正在返回我只是 index.php 作为文件下载。

提前致谢!

使用嵌套位置块以获得更简洁的解决方案。请注意 ^~ 修饰符以避免任何歧义。有关更多信息,请参阅 this document

尝试:

location ^~ /notes {
    alias /var/www/paperwork/frontend/public;
    index index.php index.html index.htm;

    if (!-e $request_filename) { rewrite ^ /notes/index.php last; }

    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }

        fastcgi_pass unix:/var/run/php5-fpm.sock;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

有一个long standing bug regarding the use of alias with try_files. See this caution关于使用if

在使用 fastcgi_param 指令之前包含 fastcgi_params,因为它可能会默默地覆盖您的参数。