Я должен использовать www. при установке виртуальных хостов на апаче?

Если Вы знаете имена хостов или IP-адреса, можно использовать SNMP для выборки этой информации.

Только что попробовав это на нескольких моих серверов, они все отвечают своим корректным порядковым номером с командой snmpget SERVERNAME 1.3.6.1.4.1.232.2.2.2.1.0.

-1
задан 20 October 2013 в 07:10
2 ответа

Для этого не нужно создавать два отдельных хоста - просто используйте директиву ServerAlias ​​:

<Virtualhost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ...
</VirtualHost>
3
ответ дан 5 December 2019 в 19:09

I would go further than EEAA, and say that the pattern in which you put in virtual hosts is important, because you can add a single catch-all virtual host at the very end that catches everything that isn't yet caught, and adds a www in front of it.

As an example, you can set up your main level domains like this:

<Virtualhost *:80>
    ServerName www.example.com
    ...
</VirtualHost>

<Virtualhost *:80>
    ServerName www.example1.com
    ...
</VirtualHost>

And then you add any specific sub-domains right after the main domain names (assuming you even use sub-domains… I do, so it’s an issue for me):

<Virtualhost *:80>
    ServerName test.example.com
    ...
</VirtualHost>

<Virtualhost *:80>
    ServerName beta.example2.com
    ...
</VirtualHost>

And at the very end of the vhosts file you add your catch-all redirector. This redirector catches any domain name that hasn’t yet been caught and adds a www in front of it. Essentially, the vhosts file would look like this:

<Virtualhost *:80>
    ServerName *.example.com
    ServerName *.example1.com
    ServerName *.example2.com
    ...
</VirtualHost>

And then you would get some basic PHP action (within that last vhost… treat it as a separate site!) snagging the primary domain name and plunking a www in front of it before sending it as a HTTP 301 back to the client.

I don’t have the PHP code available to me right now, but I’ve done it before, and it’s as slick as snot in keeping your vhosts file slim and svelte.

The key thing is that, people type mistakes. A lot of time they will get the domain name correct, but mess up on something else. And a lot of old-timers (like me) still put in the “www” in front of the domain name by sheer force of habit. And sometimes I accidentally put in four w’s. So there is a source of issues right there. If you use subdomains, this tool can be a help there as well.

1
ответ дан 5 December 2019 в 19:09

Теги

Похожие вопросы