Apache의 파일 시스템 매핑에 대한 URL

Apache의 파일 시스템 매핑에 대한 URL

나는 에 블로그를 가지고 있습니다 mysite.tld/blog. 현재 루트의 를 통해 mysite.tld리디렉션됩니다 . 분명히 2년 전에 이것을 설정할 때 루트에 있는 파일을 작동할 수 없었습니다. 파일 시스템에서 내 블로그는 .mysite.tld/blogindex.php.httaccess/var/www/blog

이제 에 표시하고 싶은 간단한 웹사이트를 만듭니다 mysite.tld. 이는 파일을 통해 페이지를 제공하는 PHP 마이크로프레임워크를 통해 작동합니다 index.php. 이 사이트는 git repo에 있고 이 repo에서는 index.php에 있습니다 www/index.php. 새 버전으로 업데이트할 수 있도록 서버에 저장소 복제본을 갖고 싶습니다. 따라서 site에서 와 같이 복제한다고 가정하면 /var/www진입점은 에서 끝납니다 /var/www/site/www/index.php.

나는 지난 3시간 동안 이 믿을 수 없을 만큼 간단한 일을 작동시키려고 노력했지만 소용이 없었습니다. 내가 원하는 것은 URL을 /blog에 매핑 /var/www/blog하고 URL의 나머지 부분을 /에 매핑하는 것입니다 /var/www/site/index. 이를 위해 필요한 마법의 구성은 무엇입니까?

출력은 다음과 같습니다 lsb_release -a.

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty

출력은 다음과 같습니다 apache2ctl -V.

Server version: Apache/2.4.7 (Ubuntu)
Server built:   Jul 22 2014 14:36:38
Server's Module Magic Number: 20120211:27
Server loaded:  APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

출력은 다음과 같습니다 apache2ctl -M.

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)

답변1

내가 원하는 것은 URL을 /blog에 매핑 /var/www/blog하고 URL의 나머지 부분을 /에 매핑하는 것입니다 /var/www/site/index. 이를 위해 필요한 마법의 구성은 무엇입니까?

당신은 쉽게 이것을 할 수 있습니다아파치의 Alias지시어이와 같이. 귀하는 이 조언의 기반이 되는 Apache 2.2 및 이전 버전과 구문이 약간 다를 수 있는 Apache 2.4.7을 사용하고 있는 것으로 확인되었습니다. 그러나 구문은 약간 다를 수 있지만 전반적인 개념은 여전히 ​​동일하며 Apache 2.4에 여전히 기능이 있다고 확신합니다 Alias.

이러한 항목은 기본 사이트의 Apache 구성 파일에 설정됩니다 /etc/apache2/sites-available/. 이제 이름이 지정된 파일에 있거나 /etc/apache2/sites-available/default호스트 이름에 대한 별도의 파일에 있을 수 있으므로 /etc/apache2/sites-available/mysite.tld파일을 근본적으로 수정하기 전에 구성을 확인하십시오.

이렇게 하면 모든 요청이 http://mysite.tld/blog다음에서 콘텐츠를 가져오도록 설정됩니다 /var/www/blog.

Alias /blog /var/www/blog

이렇게 하면 모든 요청이 http://mysite.tld/다음에서 콘텐츠를 가져오도록 설정됩니다 /var/www/site/index.

Alias / /var/www/site/index

이제 ; 만 필요할 수도 있습니다 Alias /blog /var/www/blog. 로 설정되어 있는 Alias / /var/www/site/index한 해당 초는 필요하지 않을 수 있습니다 .DocumentRoot/var/www/site/index

Apache 구성 설정의 작동 방식에 대한 훌륭하고 간단하며 간결한 개요이 사이트에서 찾을 수 있습니다.

관련 정보