URL для сопоставления файловой системы в Apache

1223
Jeroen De Dauw

У меня есть блог, который находится на mysite.tld/blog. В настоящее время mysite.tldперенаправляет на mysite.tld/blogчерез index.phpв корень. Очевидно, когда я установил это два года назад, я не мог заставить .httaccessфайл, который также находится в корне, работать. В файловой системе мой блог находится по адресу /var/www/blog.

Теперь я создаю простой веб-сайт, на котором я хотел бы показать mysite.tld. Он работает через микрофрейм PHP, который обслуживает страницы через index.phpфайл. У меня есть этот сайт в репозитории Git, и в этом репо 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

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

3
JakeGould

All I want to do is map URL /blog to /var/www/blog and the remainder of URL / to /var/www/site/index. What is the magical configuration I need for this?

You can easily do this with Apache’s Alias directive like this. Note that I see you are using Apache 2.4.7 which might have a slightly different syntax than Apache 2.2 and earlier which this advice is based on. But that said, while the syntax might be slightly different but the overall concepts are still the same and I am fairly confident Apache 2.4 still has Alias functionality.

These items would be set in your main site’s Apache configuration file which would be in /etc/apache2/sites-available/. Now they might be in a file named /etc/apache2/sites-available/default or in a separate file for the hostname like /etc/apache2/sites-available/mysite.tld so be sure to check your config before radically modifying the files.

This would set all requests to http://mysite.tld/blog to get content from /var/www/blog:

Alias /blog /var/www/blog 

This would set all requests to http://mysite.tld/ to get content from /var/www/site/index:

Alias / /var/www/site/index 

Now that said, you might only need the Alias /blog /var/www/blog; that second Alias / /var/www/site/index might not be needed as long as your DocumentRoot is set to /var/www/site/index.

A good, simple and concise overview of how Apache config setups work can be found on this site.