You are not logged in.
Hello,
I am trying to set up nginx inside my LAN to have Owncloud installed in a subdirectory, so I can access it with for example https://apu.local/owncloud/.
I have tried to adapt the configuration files from the documentation to serve this purpose but I think I have not fully understood it.
Since I could not manage to set this up, I tried to do this with a test folder. Not really successful. I was not able to get PHP to run inside. (Getting File not found)
PHP on the root directory is working.
Here is my approach:
#user html;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Auto redirect HTTP to HTTPS
server {
listen [::]:80;
return 301 https://$host$request_uri;
}
# HTTPS server
#
server {
listen [::]:443 ssl;
server_name apu.andig.net apu.fritz.box apu.local apu localhost;
ssl on;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
client_max_body_size 10G; # set max upload size
root /srv/http/;
autoindex on;
location /test {
#root /srv/test;
alias /srv/test;
autoindex on;
location ~ /test/(.*\.php)$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$1;
include fastcgi.conf;
}
}
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $2;
fastcgi_param HTTPS on;
fastcgi_buffers 64 4K;
include fastcgi.conf;
}
}
}
I would like to have Owncloud in a subdirectory because I might install some other webapps. I think it would work if I make a new server-section for each webapp, listening to a different port but this seems like a rather dirty approach.
With google I found many questions regarding this subject but I could not manage to get it to run. Can anybody here maybe help?
Offline
Hi,
nginx's config can be rather tricky sometimes. One thing you might consider instead of different ports are virtual hosts, but about you current problem: I'd like to see some server side logs "File not found" isn't really precise and php-fom or nginx should provide more useful errors somewhere.
i'm sorry for my poor english wirting skills…
Offline
Thanks for the reply!
error log:
2014/04/20 11:42:58 [error] 9719#0: *2 open() "/srv/http/favicon.ico" failed (2: No such file or directory), client: 1234:56:789a:bcde:f123:baff:fe1d:ecce, server: apu.andig.net, request: "GET /favicon.ico HTTP/1.1", host: "apu.local"
2014/04/20 11:42:58 [error] 9719#0: *2 open() "/srv/http/favicon.ico" failed (2: No such file or directory), client: 1234:56:789a:bcde:f123:baff:fe1d:ecce, server: apu.andig.net, request: "GET /favicon.ico HTTP/1.1", host: "apu.local"
2014/04/20 11:43:03 [error] 9719#0: *2 FastCGI sent in stderr: "PHP message: PHP Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /srv/http/phpinfo.php on line 1" while reading response header from upstream, client: 1234:56:789a:bcde:f123:baff:fe1d:ecce, server: apu.andig.net, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "apu.local", referrer: "https://apu.local/"
2014/04/20 11:43:09 [error] 9719#0: *2 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 1234:56:789a:bcde:f123:baff:fe1d:ecce, server: apu.andig.net, request: "GET /test/phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "apu.local", referrer: "https://apu.local/test/"
corresponding access log:
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:42:58 +0200] "GET / HTTP/1.1" 301 184 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:42:58 +0200] "GET / HTTP/1.1" 200 510 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:42:58 +0200] "GET /favicon.ico HTTP/1.1" 404 168 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:42:58 +0200] "GET /favicon.ico HTTP/1.1" 404 168 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:43:03 +0200] "GET /phpinfo.php HTTP/1.1" 200 76992 "https://apu.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:43:08 +0200] "GET /test HTTP/1.1" 301 184 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:43:08 +0200] "GET /test/ HTTP/1.1" 200 619 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
1234:56:789a:bcde:f123:baff:fe1d:ecce - - [20/Apr/2014:11:43:09 +0200] "GET /test/phpinfo.php HTTP/1.1" 404 27 "https://apu.local/test/" "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0" "-"
Both in / and /test/ I have a file called phpinfo.php which just makes a phpinfo()-call.
Offline
The "Primary script unknown" seems to be your problem. A quick search turned up these (purple) links: http://serverfault.com/questions/418983 … ng-userdir and https://stackoverflow.com/questions/178 … with-nginx .
i'm sorry for my poor english wirting skills…
Offline
Thank you!
The problem with my /srv/test/ folder was, that it was not in open_basedir.
It is now working with the following location block:
location /test {
alias /srv/test;
autoindex on;
location ~ /test/(.*\.php)$ {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
For Owncloud I am happy with:
location /owncloud {
alias /usr/share/webapps/owncloud;
client_max_body_size 10G; # set max upload size
fastcgi_buffers 64 4K;
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;
index index.php;
error_page 403 /owncloud/core/templates/403.php;
error_page 404 /owncloud/core/templates/404.php;
location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}
location ~ /owncloud/(.*\.php)$ {
#try_files $1 = 404;
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
But I am unsure about rewrites. Also, when I add the try_files $1 = 404; directive which is described as a security function, I get 404 on the php files again:
2014/04/20 20:07:45 [error] 11088#0: *2 open() "/srv/http404" failed (2: No such file or directory), client: 2003:4d:eb02:de00:92e6:baff:fe1d:ecce, server: apu.andig.net, request: "GET /owncloud/index.php HTTP/1.1", host: "apu.local"
Offline
This server block seems to be working good for me. Open for any suggestions though
Owncloud is running inside the subdirectoy /owncloud/, seen from the root directory of the server block /usr/share/nginx/html/cloud. So actually the files are in /usr/share/nginx/html/cloud/owncloud/.
Hope it helps.
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /etc/ssl/certs/server.pem;
ssl_certificate_key /etc/ssl/certs/server.key;
ssl_prefer_server_ciphers on;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
access_log /var/log/nginx/localhost_ssl.access.log;
root /usr/share/nginx/html/cloud;
location / {
index index.html index.htm index.php;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /owncloud {
#index index.html index.htm index.php;
#rewrite ^/owncloud/.well-known/carddav /remote.php/carddav/ redirect;
#rewrite ^/owncloud/.well-known/caldav /remote.php/caldav/ redirect;
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;
rewrite ^/owncloud/apps/calendar/caldav.php /remote.php/caldav/ last;
rewrite ^/owncloud/apps/contacts/carddav.php /remote.php/carddav/ last;
rewrite ^/owncloud/apps/([^/]*)/(.*\.(css|php))$ /index.php?app=$1&getfile=$2 last;
rewrite ^(/owncloud/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ index.php;
}
#error_page 404 errors/404.html;
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;
location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
#enabling php and processing files with fastcgi (changed for owncloud)
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
Offline
Thanks, but in the meantime I have given up on this topic. Owncloud runs fine on a subdomain now
I include this file in the http section of my nginx.conf along with some other files:
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name owncloud.*;
server_tokens off;
include /etc/nginx/ssl.conf;
access_log /var/log/nginx/owncloud_access.log;
error_log /var/log/nginx/owncloud_error.log;
# Path to the root of your installation
root /usr/share/webapps/owncloud;
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;
index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}
location / {
# 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;
try_files $uri $uri/ index.php;
}
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$1;
fastcgi_param PATH_INFO $2;
fastcgi_param HTTPS on;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
}
# 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;
}
}
Offline