Apache FAQ

redirect port proxy apache ServerName domain name

Q1: ServerName

При просмотре статуса сервиса apache выдается сообщение, что не обнаружено имя FQDN сервера:

* Starting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Решение 1:

Добавить директиву ServerName

sudo sh -c 'echo "ServerName "$(uname -n) >> /etc/apache2/conf.d/name' && sudo service apache2 restart

Q2: Не работает редирект

Не работает apache2 редирект с хост машины на определенный порт гостевой машины.

|Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.Apache/2.2.22 (Ubuntu) Server at .... Port 80
В логах:

[warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

Решение 2:

sudo a2enmod proxy proxy_balancer proxy_http

Q3: Редирект при ошибках в URL

Как сделать редирект на главную страницу сайта с случае возникновения ошибок 403?

Решение 3:

Включить mod_rewrite:

a2enmod rewrite
service apache2 restart

Включить поддержку .htaccess в каталоге сайта - директива Directory - AllowOverride ALL

<VirtualHost *:80>

     ServerAdmin webmaster@localhost
     ServerName bibel.ru
     DocumentRoot /home/ubuntu/react/react-project/build

     ErrorLog ${APACHE_LOG_DIR}/bibel_err.log
     CustomLog ${APACHE_LOG_DIR}/bibel_acc.log combined

     <Directory /home/ubuntu/react/react-project/build>
             AllowOverride ALL
     </Directory>

</VirtualHost>

Прописать редирект 403, 404 ошибок на index.html

ErrorDocument 404 /index.html
ErrorDocument 403 /index.html