我在让Nginx识别和重定向两个不同的域名(特别是托管在www.webapptest1.tk Freenom上的www.webapptest2.tk和Freenom上的域名)以分离不同文件夹中的index.html文件时遇到了问题。
下面是我的文件结构和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转发 (类似于Webapptest2)
现在,访问www.webapptest1.tk或www.webapptest2.tk,我得到了Webapptest1的index.html页面。
问题是,我对本地hosts文件进行了修改,使其包括Nginx服务器IP以及两个域名。在这种情况下,两个链接都被重定向到各自的index.html页面。如果没有修改hosts文件,这两个链接都只显示Webapptest1 1的index.html页面。
我认为问题就在Freenom的端,以及它重定向URL的方式,而不是我的Nginx服务器?
发布于 2017-09-28 13:46:48
通过像以前一样配置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 https://stackoverflow.com/questions/46466922
复制相似问题