Acabei de instalar o nginx com o php5-fpm e consegui que tudo funcionasse bem com um único servidor vhost.
Acabei de adicionar um servidor secundário para uma instalação wordpress (nome de domínio diferente) e quando eu vou para ele, ele sempre redireciona para o primeiro vhost que tem trabalhado o tempo todo. A parte estranha é que nos logs de erro eu posso ver isso falhando ao carregar o conteúdo do wp-content mas tentando puxá-lo do primeiro domínio ...
Primeiro domínio e um que sempre funciona:
server {
listen 80;
server_name domain1.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
# Change these settings to match your machine
listen 443;
server_name domain1.com;
# Everything below here doesn't need to be changed
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /data/www/domain1.com/www/;
index index.html index.htm index.php;
ssl on;
ssl_certificate /data/ssl/domain1.pem;
ssl_certificate_key /data/ssl/domain1.key;
ssl_session_timeout 5m;
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(?:ico|css|js|gif|inc|txt|gz|xml|png|jpe?g) {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location / { try_files $uri $uri/ @rewrites; }
location @rewrites {
rewrite ^/([^/\.]+)/([^/]+)/([^/]+)/? /index.php?page=$1&id=$2&subpage=$3 last;
rewrite ^/([^/\.]+)/([^/]+)/?$ /index.php?page=$1&id=$2 last;
rewrite ^/([^/\.]+)/?$ /index.php?page=$1 last;
}
location /admin { }
location /install { }
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# The next two lines should go in your fastcgi_params
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Segundo domínio que redireciona para o primeiro domínio, mas os recursos estão tentando carregar:
server {
listen 80;
server_name domain2.com;
# Everything below here doesn't need to be changed
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /data/www/domain2.com/public_html/;
index index.html index.htm index.php;
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location ~* \.(?:ico|css|js|gif|inc|txt|gz|xml|png|jpe?g) {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# The next two lines should go in your fastcgi_params
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Registro de erros mostrando a tentativa de extrair o recurso certo, mas do domínio errado:
2012/03/11 18:48:45 [error] 29093#0: *26 open() "/data/www/domain1.com/www/wp-content/themes/minimalist/styles/grey.css" failed (2: No such file or directory), client: 60.225.81.244, server: domain1.com, request: "GET /wp-content/themes/minimalist$