我如何告诉 Apache 指向 127.0.0.1
到特定文件夹,如 /var/www/projects/mysite1/
?
我使用sudo gedit /etc/apache2/apache2.conf
这是我的配置:
<Directory />
Options FollowSymLinks
AllowOverride all
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
所以如果我改变/var/www/
至/var/www/projects/mysite1/
我尝试访问 http://127.0.0.1/
重新启动服务器后,在我的浏览器上出现此错误:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at 127.0.0.1 Port 80
有什么想法我应该做什么吗?
最佳答案
我认为实现这一目标的最佳方法是创建 VirtualHost。
在
/etc/apache2/sites-available
中,创建一个mysite1.conf
文件。在那里,您应该具有以下配置:<VirtualHost 127.0.0.1:80> ServerName localhost ServerAdmin webmaster@localhost DocumentRoot /var/www/projects/mysite1/ <Directory /var/www/projects/mysite1/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/mysite1_error.log CustomLog ${APACHE_LOG_DIR}/mysite1_access.log combined </VirtualHost>
禁用默认 VirtualHost 并启用创建的 VirtualHost:
sudo a2dissite 000-default.conf sudo a2ensite mysite1.conf
重新加载 apache 服务:
sudo service apache2 reload
关于Linux Apache 配置 - 您无权访问/在此服务器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761795/