【发布时间】:2017-05-23 05:42:23
【问题描述】:
我花了几天时间试图弄清楚如何使用 nginx 在我的 Ubuntu 14.04 服务器上设置多个域。
在我的 /etc/nginx/sites-available/default 文件中:
#Domain + IP one.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/alive.gg/html;
index index.php index.html index.htm;
#149.202.86.66 IP ONE
server_name alive.gg www.alive.gg;
location / {
try_files $uri $uri/ =404;
}
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#Domain + IP two
server {
listen 80;
listen [::]:80;
root /var/www/blazeplay.com/html;
index index.php index.html index.htm;
#213.186.35.171 IP TWO
server_name blazeplay.com www.blazeplay.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我的 /etc/network/interfaces 文件
auto eth0
iface eth0 inet static
address 149.202.86.66
netmask 255.255.255.0
network 149.202.86.0
broadcast 149.202.86.255
gateway 149.202.86.254
post-up /sbin/ifconfig eth0:0 213.186.35.147 netmask 255.255.255.255 br$
post-down /sbin/ifconfig eth0:0 down
post-up /sbin/ifconfig eth0:1 213.186.35.167 netmask 255.255.255.255 br$
post-down /sbin/ifconfig eth0:1 down
post-up /sbin/ifconfig eth0:2 213.186.35.171 netmask 255.255.255.255 br$
post-down /sbin/ifconfig eth0:2 down
最后一个是我尝试使用的第二个 IP。 (213.186.35.171)
我已经重定向了我的域 DNS,例如 Blazeplay.com:
A @ 213.186.35.171
当我访问 Blazeplay.com 时会发生什么:
我可以查看正确的页面 /var/www/blazeplay.com/html - 但是它无法加载 CSS IMG 等,它会引发 404 错误。如果我访问我的 wordpress 登录站点 /wp-admin,它会将我重定向到正确的 IP,但是当我按 Enter 时,它会再次将我重定向到 alive.gg 域。又名default_server,所以自从它转向default_server 后,我一定设置错了。这就是我迷失在做什么的地方。因为,如果我将server_name blazeplay.com www.blazeplay.com; 替换为 IP 地址 213.186.35.171,而不是域,所有内容都可以正常加载,没有任何问题。
请随意尝试上述方法,所有设置仍然相同,因此如果您前往 blazeplay.com/wp-admin 域并尝试登录,您应该也会遇到同样的情况。
我不是 Ubuntu 或 nginx 专家,我是否错过了配置多个域的一些小步骤,或者我可以做一些故障排除来定位我的问题吗?非常感谢任何帮助!
如果您需要任何其他信息,请告诉我。 :-)
感谢您的阅读。
【问题讨论】:
标签: ubuntu nginx dns ubuntu-14.04 multiple-domains