Estou tentando usar o nginx como um servidor da Web para minha instalação do owncloud. De acordo com este tutorial , criei o seguinte arquivo de configuração:
server {
listen 59476;
server_name mydomain.de;
root /home/owncloud/www/;
access_log /home/owncloud/log/nginx.access.log;
error_log /home/owncloud/log/nginx.error.log debug;
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 = /favicon.ico {
access_log off;
log_not_found 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_pass unix:/var/run/php5-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;
}
}
Mas quando eu visito o site http://mydomain.de:59476
, recebo apenas a mensagem de erro "Arquivo não encontrado". Como configurei o nível de depuração como "debug", recebo o seguinte link do arquivo de log. Eu acho que a linha mais importante é
2013/08/03 17:23:21 [error] 29508#0: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 37.24.146.15, server: mydomain.de, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.de:59476"
Qual, como entendi nginx, significa que o arquivo que o nginx tenta executar não existe. Mas o log também disse:
2013/08/03 17:23:21 [debug] 29508#0: *3 fastcgi param: "SCRIPT_FILENAME: /home/owncloud/www/index.php"
e o arquivo /home/owncloud/www/index.php
existe.
Para verificar se o nginx sozinho funciona corretamente, configurei outro website sem o owncloud e tudo funciona perfeitamente (incluindo suporte ao PHP) com a seguinte configuração:
server {
listen 59477;
server_name mydomain.net;
root /home/born/web/nginx;
index index.php;
# Logging --
access_log /home/myuser/logs/nginx.access.log;
error_log /home/myuser/logs/nginx.error.log notice;
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
access_log off;
expires max;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
e os seguintes fastcgi_params
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;