1

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

我的工作树如下所示:

/var/www/
|-> 网站
|-> nextcloud
|-> 文书工作

我的主页可以通过 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作为文件下载。

提前谢谢!

4

1 回答 1

1

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

尝试:

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

关于with的使用存在一个长期存在的错误。请参阅此使用注意事项。aliastry_filesif

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

于 2017-05-14T17:27:43.133 回答