URL과 같은 하위 폴더가있는 Apache의 가상 호스트
-
14-11-2019 - |
문제
도메인 이름을 사용하여 Apache에서 Vhosts를 가질 수 있다면 관심이 있습니다. http://something.com/something 또는 http : // {server-ip-address-here} / 뭔가 ?
Ubuntu Server에서 Apache 2.2.20을 사용하고 있습니다. 내 홈 서버는 여기에서 일부 물건을 테스트하고 있습니다. 여기에 DNS 서버가 있고 공용 IP 주소 만 있고 도메인 이름이 첨부 된 도메인 이름입니다. DNS 서비스를 엽니 다.
그래서, 내가 무엇을 했는가 :
- 나는 / etc / apache2 / sites - 사용 가능한 에 새로운 파일 "데모"를 만들었습니다.
-
실제로 이것은 기본 파일에서 수정 된 상태로 복사됩니다.
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName {mydomain-here}/demo/ DocumentRoot /vhosts/demo <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /vhosts/demo/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
-
/ etc / apache2 / sites가 활성화 된 / etc / apache2 / sites-available / demo
-
생성 /vhosts/demo/index.html 파일.
이제 내가 얻는 것은 내가 {my-domain}에 가면 내가 만든 Vhost에 가서 문제는 {my-domain} / demo뿐만 아니라 서버에서 그 서버가 나를 가리키는 문제입니다. 나는 원한다.
결론적으로 다른 가상 호스트를 만들고 동일한 기본 URL, 예를 들어 www.mydomain.com/vhost1, www.mydomain.com/vhost2 등의 다른 URL에 연결할 수 있습니다. < / P>
가 가능합니까? 감사합니다 :)
해결책
To start, the reason why it goes there is ANY case is cause you have you have a *:80 setting for your virtual host, so if nothing matches the request it uses the first virtual host entry
If I understand what you are trying to do it appears like you might just want to alias each 'virtual host'
What you are trying to do isn't quite a virtual host (at least what a virtual host is supposed to do), but you might be able to accomplish it by using alias feature of apache
Alias /vhost1 /whatever/folder/your/vhost1/site/is/at
Alias /vhost2 /whatever/folder/your/vhost2/site/is/at
So now whatever domain you use e.g. http://whatever.com/vhost1 or http://whatever.com/vhost2 The both of em will appear as separate sites