Centos 7의 여러 가상 호스트가 함께 작동하지 않습니다

Centos 7의 여러 가상 호스트가 함께 작동하지 않습니다

내 서버 정보는

Server version: Apache/2.4.6 (CentOS)
Server built:   Nov 19 2015 21:43:13

동일한 서버에서 호스팅되는 biz.example.com 및 pin.example.com이라는 두 개의 다른 사이트에 대한 가상 호스트를 구성하려고 합니다. 'var/www/html/' 아래에 'biz' 및 'pin'이라는 이름의 2개의 다른 폴더가 있으며 위에서 언급한 2개의 웹 사이트에 대한 관련 프로젝트 파일이 있습니다. 아래 방법으로 구성하려고 합니다.

/etc/hosts 아래 구성 내에서

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

xxx.xxx.xxx.xxx biz.example.com
xxx.xxx.xxx.xxx pin.example.com

xxx.xxx.xxx.xxx는 서버 IP 주소로 대체됩니다.

/etc/httpd/conf/httpd.conf 내에서

IncludeOptional sites-enabled/*.conf

이제 /etc/httpd/sites-available 아래에 biz.conf 및 pin.conf 파일이 있습니다. 또한 아래 명령을 사용하여 사이트 사용 가능 폴더의 biz.conf 및 pin.conf를 가리키는 2개의 파일이 있는 /etc/httpd 아래에 sites-enabled 폴더가 있습니다.

ln -s /etc/httpd/sites-available/biz.conf /etc/httpd/sites-enabled/biz.conf

ln -s /etc/httpd/sites-available/pin.conf /etc/httpd/sites-enabled/pin.conf

biz.conf에는 다음이 있습니다

<VirtualHost *:80>
ServerName http://biz.example.com/
ServerAlias http://biz.example.com/
DocumentRoot "/var/www/html/biz"
<directory "/var/www/html/biz">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from 127.0.0.1
</directory>
</VirtualHost>

그리고 pin.conf 파일 내의 구성은 다음과 같이 언급됩니다.

<VirtualHost *:80>
ServerName http://pin.example.com/
ServerAlias http://pin.example.com/
DocumentRoot "/var/www/html/pin"
<directory "/var/www/html/pin">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from 127.0.0.1
</directory>
</VirtualHost>

이 설정에서 액세스하려고 하면http://biz.example.com/, 올바른 웹사이트(비즈니스 웹사이트)가 로드 중입니다. 하지만 내가 접근하려고 하면http://pin.example.com/, 그러면 핀 웹사이트 대신 비즈니스 웹사이트가 로드됩니다. 여러 구성이 함께 작동하지 않습니다.

또한 biz.conf와 pin.conf의 가상 구성을 단일 파일 biz.conf 내에서 병합하려고 시도했지만 제대로 작동하지 않았습니다.

답변1

답변:

1) ServerName 및 ServerAlias에서 후행 슬래시를 제거해야 합니다.

2) 여기서는 ServerAlias를 제거할 수 있으며 ServerName과 ServerAlias는 모두 동일합니다.

답변2

경로에서 큰따옴표를 제거하세요.

DocumentRoot /var/www/html/pin
<directory /var/www/html/pin>

답변3

이 설정에서 액세스하려고 하면http://biz.example.com/, 올바른 웹사이트(비즈니스 웹사이트)가 로드 중입니다. 하지만 내가 접근하려고 하면http://pin.example.com/, 그러면 핀 웹사이트 대신 비즈니스 웹사이트가 로드됩니다.

그 이유는 지시문 ServerNameServerAlias지시문이 모두 일치하지 않고(잘못된 구문) 이 경우 첫 번째 정의가 VirtualHost모든 요청을 가져오기 때문입니다.

동작은 매우 유사한 구성으로 문서에 설명되어 있습니다.

단일 IP 주소에서 여러 이름 기반 웹 사이트 실행(httpd.apache.org/docs/2.4/vhosts/examples.html)

# Ensure that Apache listens on port 80
Listen 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>

별표는 모든 주소와 일치하므로 기본 서버는 요청을 처리하지 않습니다. 구성 파일에서 가상 호스트가 첫 번째이기 때문에 ServerName www.example.com우선 순위가 가장 높으며 다음과 같이 볼 수 있습니다.기본또는주요한섬기는 사람. 즉, 지정된 ServerName지시어 중 하나와 일치하지 않는 요청이 수신되면 이 먼저 처리됩니다 <VirtualHost>.


해결책:

  1. 접두사와 후행 슬래시가 없어야 ServerName합니다 . 즉,http://

    ServerName biz.example.com
    

    그리고

    ServerName pin.example.com
    
  2. ServerAlias와 같은 값을 가지므로 제거할 수 있습니다.ServerName

  3. <Directory></Directory>대문자로 시작해야 합니다

  4. 이전 Apache 2.2 액세스 제어 구문은 새로운 Apache 2.4 Require구문으로 변경되어야 합니다.

    Order Deny,Allow
    Allow from 127.0.0.1
    

    로 교체해야합니다

    Require local
    

    보다


관련 정보