Может ли DNS-имя домена указывать на папку на сервере?

11702
Ryan

Итак, у меня есть доменное имя DNS для моего компьютера, чтобы я мог легко подключиться к нему, не помня каждый раз мой IP-адрес, и он отлично работает. У меня также есть веб-сайт, размещенный на моем компьютере, для которого у меня есть доменное имя. Доменное имя имеет параметр переадресации URL, Frame(cloaking)который указывает на папку моего сайта.

У меня есть часть входа на мой сайт, который использует сессии php. Когда я захожу на localhost, чтобы протестировать сессию, она работает нормально. Но когда я использую свое доменное имя, оно не работает вообще. Поэтому я попытался использовать свое DNS-имя и поместить папку после него example.tk/MySite. К моему удивлению это сработало. Но если я не /MySiteввожу после DNS-имени, это идет к MAMP Index of /. Я не хочу этого вообще. Мне было интересно, если можно перенаправить DNS-имя домена в папку. Я посмотрел это, и люди сказали нет, вы должны настроить «Виртуальный хостинг» или что-то еще. Теперь я очень мало знаю обо всем этом в Домене, поэтому любая помощь будет принята с благодарностью.

Заранее спасибо!

Где я разобрался с виртуальным хостингом.

2
DNS - это «Система доменных имен» и ничего более, вы должны прочитать http://en.wikipedia.org/wiki/Domain_Name_System. PHP, URL-адреса, связанные с Интернетом, поэтому веб-сервер должен позаботиться о «указании» на папку на сервере. alexus 9 лет назад 0

3 ответа на вопрос

6
joeqwerty

Q: Can a DNS domain name point to a folder on a server?

A: No.

Возможно, я не говорю это правильно, но я подумал, что доменное имя указывает на определенную папку, обычно называемую «DocumentRoot» во многих системах. Kevin Fegan 8 лет назад 0
0
Mark Stosberg

DNS cannot forward to a folder.

There are some options to solve this a different way.

First, many DNS providers allow you to set up "HTTP redirection" for a DNS name. What's actually happening with this feature is that the DNS is pointing to the provider's web server, where they have a simple web server configuration set up to provide the HTTP redirection portion.

You could use the approach yourself: Point the DNS to a server where you are running a web server that is configured to respond to the same domain name, by either displaying or redirecting to a folder. The details vary significantly based on the details of your situation.

0
Hagen von Eitzen

The behavour you observe is exactly as expected. Note that an URL like http://example.tk:80/MySite means that the client has to contact the host example.tk (and only to find out whyich host that refers to is what DNS is used for in this context), then initiate a TCP connection to a server process listening on port 80 of that host, then use the http protocol to request the URI /MySite from example.tk. The typical webserver will interprete such a path-like URI as a path relative to its document root and for exmample return the content of a file of that name (or execute a php script or list the contents of a directory [in fact after a redirection] or whatever you configure).

So since you are almost happy with the result - just off a directory level - I suggest you reconfigure your webserver to serve from a different document root. On the other hand, your report about http://localhost doing the right thing suggests that you already have virtual hosting set uop, i.e., the vhost localhost is configured to use that MySite folder as its document root. It should be possible to modify the configuration of your example.tk host to serve from the very same document root. Maybe start reading through the vhost-specific configuration files of your webserver (probably located in /etc/apache2/sites-enabled or similar). Look out especially for DocumentRoot options, of course.

Когда я использую localhost, я действительно набираю localhost / MySite, а не localhost. Изменит ли это корневой уровень, о котором вы говорили? Ryan 9 лет назад 0