Estou com um problema ao migrar um website do Apache para o nginx. A maioria das coisas funciona bem, eu só tenho um problema muito específico com alguns arquivos estáticos aqui.
No docroot do servidor, um phpBB é instalado, e os arquivos .css do tema são canalizados através do interpretador PHP, em vez de serem diretamente entregues pelo nginx, e eu não consigo entender o porquê.
Minha configuração do site nginx:
server {
listen 81; ## listen for ipv4
listen [::]:81 default ipv6only=on; ## listen for ipv6
server_name www.wanda.eu;
access_log /var/log/nginx/wanda.eu.access.log;
error_log /var/log/nginx/wanda.eu.error.log debug;
root /srv/www/wanda.eu;
location /static {
try_files $uri $uri/ @php_index =404;
expires 24h;
}
location / {
#Secure arbitrary code execution on NON php files (ex: .png with PHP code)
fastcgi_index index.php;
try_files $uri $uri/ /index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name;
}
location /dynamic {
#Secure arbitrary code execution on NON php files (ex: .png with PHP code)
try_files $uri $uri/ /dynamic/index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name;
}
}
(o bloco dinâmico é um bloco especial para o site que está configurado lá, que gera imagens - o que está funcionando bem)
O problema aqui é ao solicitar o url /forum/styles/bastisstyle/theme/stylesheet.css
Com a depuração ativada no error_log, vejo o seguinte:
2012/08/08 16:24:20 [debug] 13885#0: *669 http request line: "GET /forum/styles/bastisstyle/theme/stylesheet.css HTTP/1.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 http uri: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http args: ""
2012/08/08 16:24:20 [debug] 13885#0: *669 http exten: "css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http process request header line
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Host: www.wanda.eu:81"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept: text/css,*/*;q=0.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept-Language: en-us,en;q=0.5"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept-Encoding: gzip, deflate"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Connection: keep-alive"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Referer: http://www.wanda.eu:81/forum/"
2012/08/08 16:24:20 [debug] 13885#0: *669 http alloc large header buffer
2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 0000000001469B00:256
2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 0000000001497800:8192
2012/08/08 16:24:20 [debug] 13885#0: *669 http large header alloc: 0000000001497800 8192
2012/08/08 16:24:20 [debug] 13885#0: *669 http large header copy: 693
2012/08/08 16:24:20 [debug] 13885#0: *669 recv: fd:17 214 of 7499
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Pragma: no-cache"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Cache-Control: no-cache"
2012/08/08 16:24:20 [debug] 13885#0: *669 http header done
2012/08/08 16:24:20 [debug] 13885#0: *669 event timer del: 17: 1344435925526
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 0
2012/08/08 16:24:20 [debug] 13885#0: *669 add cleanup: 00000000014972F8
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 1
2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "/"
2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "static"
2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "dynamic"
2012/08/08 16:24:20 [debug] 13885#0: *669 using configuration "/"
2012/08/08 16:24:20 [debug] 13885#0: *669 http cl:-1 max:1048576
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 3
2012/08/08 16:24:20 [debug] 13885#0: *669 post rewrite phase: 4
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 5
2012/08/08 16:24:20 [debug] 13885#0: *669 add cleanup: 0000000001497330
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 6
2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 7
2012/08/08 16:24:20 [debug] 13885#0: *669 access phase: 8
2012/08/08 16:24:20 [debug] 13885#0: *669 access phase: 9
2012/08/08 16:24:20 [debug] 13885#0: *669 post access phase: 10
2012/08/08 16:24:20 [debug] 13885#0: *669 try files phase: 11
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 try to use file: "/forum/styles/bastisstyle/theme/stylesheet.css" "/srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 try file uri: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 000000000152A140:4096
2012/08/08 16:24:20 [debug] 13885#0: *669 http init upstream, client timer: 0
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "QUERY_STRING"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "QUERY_STRING: "
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REQUEST_METHOD"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "GET"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REQUEST_METHOD: GET"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "CONTENT_TYPE"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "CONTENT_TYPE: "
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "CONTENT_LENGTH"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "CONTENT_LENGTH: "
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SCRIPT_NAME"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SCRIPT_NAME: /forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REQUEST_URI"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REQUEST_URI: /forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "DOCUMENT_URI"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "DOCUMENT_URI: /forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "DOCUMENT_ROOT"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/srv/www/wanda.eu"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "DOCUMENT_ROOT: /srv/www/wanda.eu"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_PROTOCOL"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "HTTP/1.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_PROTOCOL: HTTP/1.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "GATEWAY_INTERFACECGI/1.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_SOFTWARE"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "nginx/"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "0.7.67"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_SOFTWARE: nginx/0.7.67"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REMOTE_ADDR"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "95.130.252.148"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REMOTE_ADDR: 95.130.252.148"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REMOTE_PORT"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "62676"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REMOTE_PORT: 62676"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_ADDR"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "109.75.187.90"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_ADDR: 109.75.187.90"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_PORT"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "81"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_PORT: 81"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_NAME"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "www.wanda.eu"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_NAME: www.wanda.eu"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REDIRECT_STATUS200"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REDIRECT_STATUS: 200"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SCRIPT_FILENAME"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "/srv/www/wanda.eu"
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SCRIPT_FILENAME: /srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http cleanup add: 000000000152A9E8
2012/08/08 16:24:20 [debug] 13885#0: *669 get rr peer, try: 1
2012/08/08 16:24:20 [debug] 13885#0: *669 socket 44
2012/08/08 16:24:20 [debug] 13885#0: *669 epoll add connection: fd:44 ev:80000005
2012/08/08 16:24:20 [debug] 13885#0: *669 connect to unix:/tmp/php-cgi/php-cgi.socket, fd:44 #684
2012/08/08 16:24:20 [debug] 13885#0: *669 connected
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream connect: 0
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream send request
2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer buf fl:0 s:1816
2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer in: 000000000152AA20
2012/08/08 16:24:20 [debug] 13885#0: *669 writev: 1816
2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer out: 0000000000000000
2012/08/08 16:24:20 [debug] 13885#0: *669 event timer add: 44: 60000:1344435920767
2012/08/08 16:24:20 [debug] 13885#0: *669 http run request: "/forum/styles/bastisstyle/theme/stylesheet.css?"
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream check client, write event:1, "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream recv(): -1 (11: Resource temporarily unavailable)
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream request: "/forum/styles/bastisstyle/theme/stylesheet.css?"
2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream process header
2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 000000000152FAB0:32768
2012/08/08 16:24:20 [debug] 13885#0: *669 recv: fd:44 12488 of 32768
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 01
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 06
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 01
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 1F
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: F8
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record length: 8184
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi parser: 0
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi header: "X-Powered-By: PHP/5.3.3-7+squeeze13"
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi parser: 0
2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi header: "Content-type: text/html"
... e muito mais linhas, que indicam que ele é enviado pelo nginx.
O problema é que o tipo de conteúdo é definido como text / html e, muito claramente, o interpretador do php é executado para a folha de estilo, o que é absolutamente desnecessário.
Especialmente essas linhas aqui me dão um loop:
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 try to use file: "/forum/styles/bastisstyle/theme/stylesheet.css" "/srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css"
2012/08/08 16:24:20 [debug] 13885#0: *669 try file uri: "/forum/styles/bastisstyle/theme/stylesheet.css"
O nginx está procurando pelo arquivo correto no local correto, mas parece não reconhecê-lo. Não é um problema de permissão, como eu posso abrir o arquivo quando eu su para o usuário www-data (que é o usuário nginx).
Qualquer ajuda aqui, porque o servidor está mostrando esse comportamento, seria muito apreciada.
Atenciosamente,
Jens
EDIT 1
Eu acho que resolvi isso sozinho, embora eu não tenha uma idéia real de como essa configuração é tão diferente da primeira, e porque o comportamento no primeiro exemplo de configuração era como eu descrevi. Tentei consertar outro problema que tive com esse site e também corrigi os problemas com as folhas de estilo.
Aqui está a configuração que funciona:
server {
listen 81; ## listen for ipv4
listen [::]:81 default ipv6only=on; ## listen for ipv6
server_name www.wanda.eu;
access_log /var/log/nginx/wanda.eu.access.log;
error_log /var/log/nginx/wanda.eu.error.log debug;
root /srv/www/wanda.eu;
index index.php index.html;
location /static {
try_files $uri $uri/ @php_index =404;
expires 24h;
}
location / {
try_files $uri $uri/ $uri/index.html $uri/index.htm @php;
}
location /dynamic {
try_files $uri $uri/ /dynamic/index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name;
}
location @php {
try_files $uri /index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name;
}
location ~ \.php$ {
try_files $uri /index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name;
}
}