
/etc/apache2/sites-available/mysite.conf를 만듭니다.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# 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 /home/USER/www/public_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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
그런 다음 나는 다음을 수행합니다.
sudo a2dissite 000-default && sudo a2ensite mysite
sudo service apache2 reload
이제 grep -R "DocumentRoot" /etc/apache2/sites-enabled를 수행하면 다음과 같이 응답합니다.
/etc/apache2/sites-enabled/mysite.conf: DocumentRoot /home/USER/www/public_html
/home/USER/에서 ls -l을 수행하면 다음과 같이 응답합니다.
drwxr-xr-x 3 USER USER 4096 giu 10 20:23 www
/home/USER/www에서 ls -l을 수행하면 다음과 같이 응답합니다.
drwxr-xr-x 2 USER USER 4096 giu 16 12:05 public_html
하지만 내가 가면http://로컬호스트/그것은 다음과 같이 응답합니다:
Forbidden
You don't have permission to access / on this server.
-----------------------------------------------------
Apache/2.4.29 (Ubuntu) Server at localhost Port 80
왜?
답변1
Apache에는 사이트가 호스팅되는 파일 시스템의 루트까지 모든 디렉터리에 대한 권한이 필요합니다.
/home
사용자가 소유하지 않고 루트가 소유합니다.- /home 권한을 root:root에서 USER:USER로 변경하면 시스템이 중단됩니다.
따라서 아니오: Apache에 대해 /home/USER/www/를 설정하는 것은 좋은 생각이 아닙니다. 기본값인 /var/www/를 사용하세요./var/www/
필요한 것은 에서 까지의 SYMLINK뿐입니다 /home/USER/wwww/
.
.conf에 누락된 부분이 있습니다. <Directory "/directory/documentroot">
태그와 가 누락되었습니다 Require all granted
.