Nginx的虚拟主机不正确重定向,这两个网站重定向到第一列在服务器中启用站点配置
我有(托管在Freenom专门www.webapptest1.tk
和www.webapptest2.tk
)获得Nginx的认识和重定向两个不同的域名,一个问题将不同文件夹中的index.html
文件分开。Nginx的虚拟主机不正确重定向,这两个网站重定向到第一列在服务器中启用站点配置
这是我的文件结构和Nginx的sites-enabled
配置:
Webapptest1 HTML
目录:/var/www/webapptest1.tk/html/index.html/
<html>
<head>
<title>indexTest</title>
</head>
<body>
<center><h1>Welcome to webapptest1</h1></center>
<center><p>This webpage domain name is redirecting to the IP address: xx.xxx.xxx.xxx</p></center>
<center>Webapptest1 successfully redirected!</center>
</body>
</html>
Webapptest2 HTML
目录:/var/www/webapptest2.tk/html/index.html/
<html>
<head>
<title>indexTest</title>
</head>
<body>
<center><h1>Welcome to webapptest2</h1></center>
<center><p>This webpage domain name is redirecting to the IP address: xx.xxx.xxx.xxx</p></center>
<center>Webapptest2 successfully redirected, and is NOT serving the same file as Webapptest1!</center>
</body>
</html>
启用网站,Nginx的虚拟主机配置
注:出于测试目的,我没有符号链接从网站可用
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
server {
listen 80;
server_name webapptest1.tk;
root /var/www/webapptest1.tk/html;
index index.html index.htm;
location/{
try_files $uri $uri/ =404;
}
}
server {
listen 80;
server_name webapptest2.tk;
root /var/www/webapptest2.tk/html;
index index.html index.htm;
location/{
try_files $uri $uri/ =404;
}
}
上的文件Freenom(我正在使用的域名提供商),我已经通过IP地址将域的URL转发到Nginx服务器,如下所示:
Webapptest1 URL Forwarding(类似的Webapptest2)
现在,无论是参观还是www.webapptest1.tk www.webapptest2.tk,我越来越Webapptest1的index.html
页面。
事情是,我测试了修改我的本地hosts
文件以包含Nginx服务器IP以及两个域名。在这种情况下,这两个链接都被重定向到其各自的页面。没有hosts
文件修改,这两个链接仅显示Webapptest1的index.html
页面。
我认为问题在于Freenom的结束以及重定向URL的方式,而不是我的Nginx服务器?
通过配置URL转发,浏览器中显示的页面是您在http://35.192.230.223/(这是nginx配置中的第一个虚拟主机)时将看到的页面。 所有你需要的是配置简单A
记录:
webapptest2.tk A 35.192.230.223
www.webapptest2.tk A 35.192.230.223
webapptest1.tk A 35.192.230.223
www.webapptest1.tk A 35.192.230.223
非常感谢您的建议,为我工作。为'www'配置'A'记录,并且两个链接都被正确地重定向。 –