我使用的是AWS(亚马逊网络服务)的EC2和Route 53以及Bitnami的LAMP(Apache,MySQL,PHP)。
我试图独立运行两个wordpress网站:
...local_path/htdocs/subsite1
...local_path/htdocs/subsite2
我想使用以下子域访问这些子网站:
subsite1.mydomain.com → ...local_path/htdocs/subsite1
subsite2.mydomain.com → ...local_path/htdocs/subsite2
此外,我想切换到哪里" mydomain.com"和" www.mydomain.com"当我想(也许一年一次或两次)。具体来说,我想在需要时在案例A和B之间切换。
Case A :
subsite1.mydomain.com -↘︎
mydomain.com ----------→ ...local_path/htdocs/subsite1
www.mydomain.com ------↗︎
subsite2.mydomain.com → ...local_path/htdocs/subsite2
Case B :
subsite1.mydomain.com → ...local_path/htdocs/subsite1
mydomain.com ----------↘︎
www.mydomain.com ------→ ...local_path/htdocs/subsite2
subsite2.mydomain.com -↗︎
我尝试在几篇互联网文章之后结合DNS(AWS Route 53),VirtualHost,mod_rewrite和/或htaccess,但它没有成功,但我认为有几种方法可以实现它。
考虑到安全性和便利性,解决此问题的最佳方法是什么?我应该怎么设置它们? 提前谢谢!
答案 0 :(得分:1)
(适用SELF-ANSWER)强>
我使用 VirtualHost 解决了这个问题。
特别是在“mydomain.com”和“www.mydomain.com”的情况下,我使用 ServerAlias 。
首先,我为我的服务器ip注册了A记录:
mydomain.com. A XXX.XXX.XXX.XXX
www.mydomain.com. A XXX.XXX.XXX.XXX
subdomain1.mydomain.com. A XXX.XXX.XXX.XXX
subdomain2.mydomain.com. A XXX.XXX.XXX.XXX
其次,在VirtualHost的配置文件中,(在我的例子中,是... / apache2 / conf / extra / httpd-vhosts.conf)
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin email1@domainX.com
DocumentRoot ...local_path/htdocs/subsite.mydomain.com/htdocs
ServerName subsite1.mydomain.com
ServerAlias subsite1.mydomain.com mydomain.com
ErrorLog "logs/subsite1.mydomain.com-error_log"
CustomLog "logs/subsite1.mydomain.com-acccess_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email2@domainY.com
DocumentRoot ...local_path/htdocs/subsite2.mydomain.com/htdocs
ServerName subsite2.mydomain.com
ServerAlias subsite2.mydomain.com www.mydomain2.com
ErrorLog "logs/subsite2.mydomain.com-error_log"
CustomLog "logs/subsite2.mydomain.com-access_log" common
</VirtualHost>
效果很好!
参考(韩国关于VirtualHost的文章)