将Nginx与Nextcloud/网站/文书工作并行使用 [英] Using Nginx with Nextcloud/Website/Paperwork parallel
问题描述
我正在尝试在不同位置运行Nextcloud,主页和文书工作,但无法弄清楚如何正确配置nginx-config.
I am trying to run Nextcloud,a Homepage and Paperwork under different locations, but can't figure out how to configure my nginx-config correctly.
我的工作树如下:
/var/www/
|->网站
|-> nextcloud
|->文书工作
/var/www/
|-> website
|-> nextcloud
|-> paperwork
我的主页可以通过web.domain.com访问,而我的Nextcloud ist可以通过cloud.domain.com访问. 现在,我想让Paperwork在web.domain.com/notes下可以访问. Paperwork的index.php位于子文件夹"paperwork/frontend/public"中.
My Homepage is reachable through web.domain.com and my Nextcloud ist reachable with cloud.domain.com. Now i want to get Paperwork to be reachable under web.domain.com/notes. The index.php of Paperwork lies in the subfolder "paperwork/frontend/public".
这是我解决这个问题的尝试(没有整个ssl和云部分):
This is my attemp to solve this (without the whole ssl and the cloud part):
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作为文件下载.
I tried out a lot different solutions but i eather get an 404 because he is using the wrong directory and can't find /var/www/notes/index.php (or similar errors) or nginx is returning me just the index.php as a file-download.
提前谢谢!
推荐答案
将嵌套的位置块用于更干净的解决方案.请注意^~
修饰符,以避免任何歧义.有关更多信息,请参见本文档.
Use nested location blocks for a cleaner solution. Note the ^~
modifier to avoid any ambiguity. See this document for more.
尝试:
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;
}
}
关于将alias
与alias
一起使用,有一个长期存在的错误. c2>.有关使用if
的信息,请参见此警告.
There is a long standing bug regarding the use of alias
with try_files
. See this caution on the use of if
.
在使用fastcgi_param
指令之前先包含fastcgi_params
,因为它可能会悄无声息地覆盖您的参数.
Include fastcgi_params
before using the fastcgi_param
directive, as it may silently overwrite your parameters.
这篇关于将Nginx与Nextcloud/网站/文书工作并行使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!