É muito estranho ver esse problema como o título descreve. Aqui estão os detalhes:
1) Criamos um registro A com "a1". Significa que subdomínio é: a1.example.com
,
2) diretório criado por "sudo nano /var/www/a1.example.com/html/"
3) Servidor criado por "sudo nano /etc/nginx/sites-available/a1.example.com"
4) Dentro do bloco do servidor, partes centrais:
server {
listen 80;
listen [::]:80;
root /var/www/a1.example.com/html;
index index.html index.htm;
server_name a1.example.com
location / {
try_files $uri $uri/ =404;
}
}
5) criou o link: sudo ln -s /etc/nginx/sites-available/a1.example.com /etc/nginx/sites-enabled/
6) sudo nano /etc/nginx/nginx.conf
, comentário: server_names_hash_bucket_size 64;
Certifique-se de que include /etc/nginx/sites-enabled/*;
esteja lá
7) reiniciado nginx: sudo service nginx restart
Ao fazer isso, o primeiro subdomínio, a1.example.com
funciona bem.
Mas quando tentei criar o segundo subdomínio, b2.example.com
seguindo as etapas exatas acima, b2.example.com
simplesmente não funciona: ele será redirecionado para a página principal, mas o URL permanecerá como b2.example.com
o que pode estar errado?
muito obrigado!
config para a1.example.com
server {
listen 80;
listen [::]:80;
root /var/www/a1.example.com/html;
index index.php index.html index.htm;
server_name a1.example.com;
rewrite ^/archives/(\d+)$ http://a1.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
config para b2.example.com
server {
listen 80;
listen [::]:80;
root /var/www/b2.example.com/html;
index index.php index.html index.htm;
server_name b2.example.com;
rewrite ^/archives/(\d+)$ http://b2.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
curl -I b2.example.com:
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Thu, 04 Feb 2016 05:54:22 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Set-Cookie: PHPSESSID=4r143k0o1m1l62p3g4vt1jrav1; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Link: <http://www.example.com/wp-json/>; rel="https://api.w.org/"
Link: <http://www.example.com/>; rel=shortlink
curl -I a1.example.com
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Thu, 04 Feb 2016 05:54:32 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Link: <http://a1.example.com/wp-json/>; rel="https://api.w.org/"
Tags nginx virtualhost subdomain