我花了几天的时间试图弄清楚如何使用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,但是当我点击输入时,它会再次将我重定向到alive.gg域。 Aka default_server
,所以我必须设置错误,因为它转向default_server
。这就是我迷失方向的地方。因为,如果我用IP地址213.186.35.171替换server_name blazeplay.com www.blazeplay.com;
,而不是域,所有内容都正确加载而没有任何问题。
随意尝试以上操作,所有设置仍然相同,所以如果你前往域名blazeplay.com/wp-admin并尝试登录同样的事情应该发生在你身上。
我不是Ubuntu或nginx专家,我错过了一些配置多个域的小步骤,还是可以通过某种方式解决问题以找到我的问题?非常感谢任何帮助!
如果您需要任何其他信息,请告知我们。 : - )
感谢您的阅读。
答案 0 :(得分:0)
根据this article,在virtual.conf(/etc/nginx/conf.d/virtual.conf)中为您的URL创建服务器块:
function addmsg20(type, msg, data) {
$('#display20').html(data);
}
function waitForMsg20() {
$.ajax({
type: "GET",
url: "liprintednotif.php",
async: true,
cache: false,
timeout: 50000,
success: function(data) {
var data = JSON.parse(data);
if(data.data.length > 0){
var res = data.data;
var printed = "<ul class='menu'>";
$.each(res, function(k, v){
var empext = v.employee_ext;
if(empext == null){
empext = "";
}else{
empext = v.employee_ext;
}
printed += "<li>" +
"<a href='#'>" +
"<h4>" +
" "+v.employee_fname + " " +
v.employee_mname+" "+v.employee_lname+" " +empext+ "<small>" +
v.status_desc+ "</small>" +"</h4>" +
"<p>" + v.subj_name + "</p>" +
"</a></li>";
})
printed += "</ul>";
}else{
printed = "";
}
addmsg20("new", data.count, printed);
setTimeout(
waitForMsg20,
1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
addmsg20("error", textStatus + " (" + errorThrown + ")");
setTimeout(
waitForMsg20,
15000);
}
});
};
$(document).ready(function() {
waitForMsg20();
});
根据您的详细信息更改root,server_name的值。希望这有帮助!
答案 1 :(得分:0)