Apache/2.2.22 VirtualHost Not Recognizing Some Domain Names - Solution
After configuring the virtual host according to "http://beyan.me/?id=104", everything worked normally at first. Later, to configure the mailbox, I changed the "
After configuring the virtual host according to "http://beyan.me/?id=104", everything worked normally at first. Later, to configure the mailbox, I changed the "/etc/hosts" and "/etc/hostname" files. Then the problem came: the virtual host configured for "beyan.me" just wouldn't be recognized, and the browser pointed to the "000-default" directory. Incidentally, the VPS from "vultr.com" I first learned about from "Lao Zuo's Blog". Because I needed to modify the registration on the Alibaba Cloud host, the customer service called to tell me my website couldn't have a message board, couldn't have commentary text. I tossed and turned for a long time, thinking I should do something for the country and the nation. The Constitution advocates freedom of speech, but Alibaba Cloud openly violates the Constitution, restricting the speech rights of a citizen of the People's Republic of China. Is this to be endured? How can it be? What dark forces lurk behind Alibaba Cloud, giving them such brazen confidence? So I must stand up, be a Chinese person defending the dignity of the Constitution, do my part, so that everyone has reason to speak and words to say. As for patriotism, I'll set that aside for now.
Speaking of the host at "vultr.com", I originally planned to use a coupon and try it for a month, but they insisted I add a credit card. After confirming a thousand times that there were no charges, I clicked next, next, next until it was done. After completing the data migration from Alibaba Cloud to this host, the first week went well: website access normal, email sending and receiving normal, except the Mac couldn't connect to the VPN (see "http://beyan.me/?id=100"). A week later, mail couldn't go out, and the website couldn't forward properly. Regarding the mail problem, I studied the logs and found "time out" errors, suspecting that configuring the VPN's "iptables" forwarding was causing the address issue. After going through unnecessary and useless operations like rebooting and reconfiguring the system, I took a chance and submitted a support ticket to "vultr.com". After receiving a reply, I searched and found people saying "vultr.com" uses simple and crude anti-spam measures. Sure enough, the SMTP port 25 was blocked. Here's the reply from support:
Hello, In order to combat spam and spamlike activities, our system requires a properly completed and vetted CC authorization form to confirm clients' identities prior to SMTP block removal. Please complete the authorization form and fax it in or scan and attach to this ticket: https://my.vultr.com/billing/cc\_auth\_form.pdf
I've now submitted the relevant information and, due to the time difference, am waiting for a result. The website forwarding issue also cost me an entire Sunday of fumbling around. Here's the virtual host configuration for reference:
<VirtualHost *:80>
ServerAdmin beyan@beyan.me
ServerName beyan.me
ServerAlias www.kitaluft.com blog.kitaluft.com kitaluft.com
ServerAlias www.beyan.me blog.beyan.me
ServerAlias www.0x97.com blog.0x97.com 0x97.com
RewriteEngine On
RewriteCond %{HTTP\_HOST} ^(www\.kitaluft\.com|blog\.kitaluft\.com|kitaluft\.com|www\.beyan\.me|blog\.beyan\.me|www\.0x97\.com|blog\.0x97\.com|0x97\.com)
RewriteRule ^(.\*)$ http://beyan.me$1 \[R=permanent,L\]
...
</VirtualHost>
As shown above, "ServerName" clearly defines "beyan.me", but visiting the site pointed to the default directory configured in "000-default". I later found a post "http://serverfault.com/questions/191218/apache-isnt-respecting-the-servername-directive-for-a-particular-site", and reading it was a real eye-opener. It turns out the virtual host defined in "000-default" has no "ServerName" field, so it uses the host's default "hostname" domain as the default server name, and since "000-default" is executed first, visiting "beyan.me" incorrectly points to the default directory.
Solution 1: Rename "/etc/apache2/sites-enabled/000-default" to "zzz-default". This solves the website access error, but it bypasses the default virtual host's configuration, so this modification is not recommended.
Solution 2: Add a line "ServerName default.com" to the virtual host configured in "000-default"; "default" doesn't need to be modified. This perfectly solves the above problem.
Finally, thanks to Google, and thanks to the experts online.
评论Comments
加载中…Loading…
留下评论Leave a comment