Apache가 다른 도메인에 어떤 앱 디렉토리를 사용할 것인지 알 수 있도록하려면 어떻게해야합니까?

StackOverflow https://stackoverflow.com/questions/1025587

문제

CodeIgniter가있는 사이트를 만들려고합니다. 이 서버에서 여러 도메인을 제공 할 것이며, 내가하려는 것은 www.example1.com의 http 요청을 www.example2.com의 요청과 분리 한 다음 올바른 응용 프로그램 폴더로 리디렉션하는 것입니다.

이것이 내 디렉토리 구조라고 말합니다.

  • 체계
    • 신청
      • 예제 1
      • 예제 2

그래서이 요청

www.example1.com/gallery/

그런 다음 exmaple1 폴더로 리디렉션됩니다.

누구 든지이 작업에 대한 코드 예제가 있습니까? 분명히 다시 쓰기 모듈을 사용해야합니다 ...

나는 Apache 문서를 둘러 보았지만 아무데도 갈 수 없었습니다. 이에 대한 자세한 정보가 필요하면 알려주세요.

도움이 되었습니까?

해결책

VirtualHost (및 Alias, Rewrite)를 사용하는 것은 주요 답변이지만 동일한 설정을 사용하여 다른 호스트를 추가/제거 할 것이라고 생각하면 다음을 고려할 것입니다. mod_macro 기준 치수. 이것은 Apache 구성을 단순화하고 복사/붙여 넣기 오류를 피하는 데 도움이되는 타사 모듈입니다.

레이아웃의 간단한 예제 다음을 정의하십시오.

<Macro vh80 name>
 <VirtualHost *:80>
   DocumentRoot /system/application/$name
   ServerName www.$name.com
   CustomLog /system/application/$name/logs/access.log virtcommon
   ErrorLog /system/application/$name/logs/error.log
 </VirtualHost>
</Macro>

그런 다음 사이트를 활성화 할 때 다음 지침을 사용하십시오.

vh80 예제 1을 사용하십시오

구성된 디렉토리를 루트로 사용하여 구성된 로깅 디렉토리를 사용하도록 www.example1.com을 설정합니다.

다른 팁

필요한 것을 불립니다 가상 호스트 www.example1.com 및 www.exaplme2.com을 각각 파일 시스템의 다른 폴더를 가리 키십시오.

추가적으로 URI에 다른 경로를 원한다면 주요 콘텐츠에 서비스를 제공하려면 다양한 대안이 있습니다.

  1. 폴더를 물리적으로 생성하고 더 이상 변경하지 마십시오

  2. 폴더에 링크 (기본 VirtualHost 루트 폴더를 가리키는 갤러리)를 물리적으로 만듭니다. 다음에 SYMLINKS 가상 호스트 옵션

  3. an을 사용하십시오 별명 가상 호스트의 지침

    Alias /gallery /
    
  4. mod_rewrite를 사용하십시오

    RewriteRule /gallery/(.*) /$1 [QSA]
    

가장 간단한 (Codeigniter 허가)는 옵션 1 또는 2입니다.

VirtualHost 문서의 스 니펫 :

Running several name-based web sites on a single IP address.

Your server has a single IP address, and multiple aliases (CNAMES) 
point to this machine in DNS. You want to run a web server for 
www.example.com and www.example.org on this machine.

Note

Creating virtual host configurations on your Apache server does 
not magically cause DNS entries to be created for those host 
names. You must have the names in DNS, resolving to your IP 
address, or nobody else will be able to see your web site. 
You can put entries in your hosts file for local testing, 
but that will work only from the machine with those hosts 
entries.

Server configuration

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

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

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

The asterisks match all addresses, so the main server serves no requests. 
Due to the fact that www.example.com is first in the configuration file, 
it has the highest priority and can be seen as the default or primary 
server. That means that if a request is received that does not match 
one of the specified ServerName directives, it will be served by this
first VirtualHost.

이것은 실제로 두 가지 질문입니다.

  1. www.example1.com 및 www.example2.com을 다르게 만드는 방법? 이것에 대한 대답은 가상 호스트 지령.

  2. /갤러리를 example1로 만드는 방법? 이것은 별명 지시문으로 수행됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top