Показать полную графическую версию : [решено] Apache It works!
Rubichek
13-09-2015, 18:39
Здравствуйте, подскажите пж как убрать It works! если перейти по IP отображается страница
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
как убрать например сделать ошибку 404
Habetdin
13-09-2015, 19:35
Rubichek, какая версия Apache, платформа? Для Apache 2.4.x на Linux: конфигурация хоста по умолчанию описана в файле /etc/apache2/sites-available/000-default.conf, в нём можно найти указание папку с файлом "It Works!", ищите по "DocumentRoot". Значение по умолчанию обычно /var/www или /var/www/html.
например сделать ошибку 404 »
Можно запретить доступ к папке - будет ошибка 403:
DocumentRoot "/var/www/example"
<Directory "/var/www/example">
Deny from all
</Directory>
Rubichek
13-09-2015, 20:28
Server version: Apache/2.2.22 (Debian) в /var/www лежит index.html c содержанием
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet. »
Если запретить доступ к /var/www/ не будут работать остальные сайты! Хочу что бы когда человек введет ip сервак то что бы ошибку получал или может запрос логина и пароля!
Habetdin
13-09-2015, 20:52
Если запретить доступ к /var/www/ не будут работать остальные сайты! »
Запрещаете только в пределах VirtualHost (http://httpd.apache.org/docs/2.2/vhosts/examples.html) по умолчанию? Приведите содержимое конфигов из /etc/apache2/sites-available/ для облегчения помощи :)
Rubichek
13-09-2015, 22:49
etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Habetdin
14-09-2015, 17:45
Rubichek, добавьте в эту конфигурацию доп. секцию VirtualHost, заменив выделенный IP на свой:
<VirtualHost *:80>
ServerName 123.123.123.123
Redirect 403 /
ErrorDocument 403 "Access denied"
DocumentRoot /dev/null/
UseCanonicalName Off
UserDir disabled
</VirtualHost>
А в существующей секции VirtualHost перечислите разрешенные доменные имена, будет что-то вроде:
<VirtualHost *:80>
# основной домен
ServerName example.com
# дополнительные (через пробел, если несколько)
ServerAlias www.example.com test.example.com
ServerAdmin webmaster@localhost
...
Rubichek
24-09-2015, 00:00
когда перегружаю apache2 ошибка
Warning: DocumentRoot [/dev/null/] does not exist
Syntax error on line 39 of /etc/apache2/sites-enabled/000-default:
Invalid command 'UserDir', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
failed!
Habetdin - может не верно вас понял добавляем тут в конце
etc/apache2/sites-available/default
или
etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerName 123.123.123.123
Redirect 403 /
ErrorDocument 403 "Access denied"
DocumentRoot /dev/null/
UseCanonicalName Off
UserDir disabled
</VirtualHost>
Habetdin
24-09-2015, 18:23
Invalid command 'UserDir' »
Удалите/закомментируйте строчку с UserDir.
etc/apache2/sites-available/default
или
etc/apache2/sites-enabled/000-default »
В тот файл, который уже есть, судя по пятому посту - default. Будет что-то вроде этого:
<VirtualHost *:80>
ServerName 123.123.123.123
Redirect 403 /
ErrorDocument 403 "Access denied"
DocumentRoot /dev/null/
UseCanonicalName Off
# UserDir disabled
</VirtualHost>
# оригинальное содержимое с прописанными доменами
<VirtualHost *:80>
# основной домен
ServerName example.com
# дополнительные (через пробел, если несколько)
ServerAlias www.example.com test.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Rubichek
24-09-2015, 19:22
Habetdin - спасибо работает когда захожу по внешнему ip Access denied. Но и когда захожу на сайт или phpmyadmin тоже Access denied
Habetdin
25-09-2015, 18:31
Rubichek, домены в ServerName и ServerAlias старой секции VirtualHost прописали? И попробуйте поменять местами две секции VirtualHost - не уверен, как Apache их обрабатывает :tomato2:
Rubichek
25-09-2015, 18:52
Часть конфига. Первый virtualhost пробовал ставить в конец та же ошибка.
<VirtualHost *:80>
ServerName 11.111.11.11
Redirect 403 /
ErrorDocument 403 "Access denied"
DocumentRoot /dev/null/
#UseCanonicalName Off
# UserDir disabled
</VirtualHost>
<VirtualHost *:80>
# основной домен
ServerName test.com
# дополнительные (через пробел, если несколько)
ServerAlias test.com www.test.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
Habetdin
25-09-2015, 23:05
#UseCanonicalName Off »
Почему закомментировали эту строку? Без отключения UseCanonicalName запросы с SERVER_NAME, отличным от IP 11.111.11.11, все равно могут обработаны этой секцией VirtualHost.
ServerAlias test.com www.test.com »
Здесь не нужен test.com, он задан как основной в ServerName, в alias достаточно версии с www.
Rubichek
26-09-2015, 17:30
Access denied - если захожу на сайты всеравно
Habetdin
28-09-2015, 08:04
Rubichek, очень странно. Раскомментировали строчку "UseCanonicalName Off", перезагрузили конфиг?
Установил Debian, в нём - Apache2 на виртуалку с IP 172.16.0.42. На этот же IP направил домены test.local, example.local и unused.local. Проверил - "It works!" Внес изменения в конфигурацию:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<VirtualHost *:80>
ServerName 172.16.0.42
Redirect 403 /
ErrorDocument 403 "Access denied"
DocumentRoot /dev/null/
UseCanonicalName Off
# UserDir disabled # mod_userdir не включен
</VirtualHost>
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName test.local
ServerAlias example.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Перезапустил веб-сервер (service apache2 restart) - по IP "Access denied", по обоим доменам из конфигурации (test и example) - "It works!". А вот по unused.local, который для теста не прописал - та же картина, что при доступе по IP - "Access denied" (что ожидаемо). Так что проблема может быть в неопознанном домене.
Заодно проверил, влияет ли в данном случае на результат порядок секций VirtualHost - оказалось, без разницы.
[hr]Проблема может быть в неопознанном домене. A-запись test.com указывает на 11.111.11.11? Apache не за проксирующим сервером?
Давайте проверим, какой SERVER_NAME получается в ходе работы Apache: закомментируйте в конфиге строчку «ErrorDocument 403 "Access denied"», после этого страница ошибки будет с дополнительной информацией, интересующая нас - внизу, под чертой (что-то вроде «Apache/2.2.15 (CentOS) Server at fanlab.org Port 80»).
Что у вас там при доступе по домену?
Rubichek
28-09-2015, 14:18
Forbidden
You don't have permission to access /test.com/ on this server.
вы правите этот конфиг etc/apache2/sites-available/default
Habetdin
28-09-2015, 17:22
В ходе дискуссии в ЛС выяснилось, что нужно заблокировать не доступ по IP, а доступ к IP с пустым pathname (а точнее, отключить листинг файлов, который вылез при удалении html-файла с "It Works!" (/var/www/html/index.html), для корневого каталога)
Один минус, добавленный в изначальный конфиг (http://forum.oszone.net/post-2552829-5.html):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
# минус перед Indexes:
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Rubichek
28-09-2015, 18:43
Habetdin Спасибо большое.
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.