我已经花了几天的时间,试图弄清楚如何使用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/interface文件
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专家,我是不是错过了配置多个域的一些小步骤,或者我可以做一些故障排除来定位我的问题?任何帮助都是非常感谢的!
如果您需要任何其他信息,请让我知道。:-)
感谢您的阅读。
发布于 2017-01-09 10:15:46
根据this article,在virtual.conf (/etc/nginx/conf.d/virtual.conf)中为您的URL创建服务器块:
server {
listen 80;
root /opt/htdocs/bestflare;
index index.html index.htm;
server_name bestflare.com;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
root /opt/htdocs/usefulread;
index index.html index.htm;
server_name usefulread.com;
location / {
try_files $uri $uri/ =404;
}
}根据您的具体情况更改root和server_name的值。希望这能有所帮助!
发布于 2017-01-09 10:54:04
天哪,花了这么多时间,我错过的就是每个服务器模块中的listen: ip:port;。
https://stackoverflow.com/questions/41539948
复制相似问题