将Apache文档根文件夹更改为辅助硬盘驱动器
我为我的服务器pc安装了ubuntu 12.04服务器版。 我安装了灯泡服务器。 我需要将var / www位置更改为我的辅助硬盘位置。 我配置了很多时间在gedit / etc / apache2 / sites-available / default这里是我的代码
ServerAdmin webmaster@localhost #DocumentRoot /var/www DocumentRoot /media/myserver/ Options FollowSymLinks AllowOverride None # Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all 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 Alias /doc/ "/usr/share/doc/" Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128
并且也使用了
sudo chown -R var/www /media/myserver/
和
chmod -R 755 /media/myserver/
仍然我无法连接我的/ media / myserver,我的浏览器显示以下消息
Forbidden You don't have permission to access / on this server.
请告诉任何人如何在我的var / www上安装myserver,谢谢提前
您必须编辑apache2.conf
和000-default.conf
来更改apache的文档根目录。
Apache服务器安装在var/www/html
。这是apache的默认根目录。
更改Apache的根目录或将项目移动到/var/www/html
。
-
要更改Apache的根目录,请运行:
cd /etc/apache2/sites-available
-
然后使用以下命令打开
000-default.conf
文件:nano 000-default.conf
-
编辑
DocumentRoot
选项:DocumentRoot /path/to/my/project
-
然后重启apache服务器:
sudo service apache2 restart
如果您获得Forbidden You don't have permission to access / on this server
在更改apache的根目录后, Forbidden You don't have permission to access / on this server
,请执行以下步骤
-
找到位于
/etc/apache2
的apache2.conf
并使用以下命令打开它:nano apache2.conf
-
使用Ctrl + W并搜索目录(它应该在第153行)
-
它看起来应该是这样的
Options Indexes FollowSymLinks AllowOverride All Require all denied -
将其更改为
Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted -
重启apache
sudo service apache2 restart
我制作了一个脚本,可以在一个命令中更改apache root。 你可以在我的github上找到它。
也许有点晚了。 但还是..
您应该在/ etc / apache2下的apache.conf中编辑目录权限
搜索这个
Options Indexes FollowSymLinks AllowOverride None Require all granted
并在其下添加此代码,它提供访问您的目录的权限
Options Indexes FollowSymLinks AllowOverride None Require all granted
只需在激活的配置中更改文档根目录即可。 /etc/apache2/sites-enabled/000-default
然后确保重新加载你的apache。
所以试试这个:
ServerAdmin webmaster@localhost DocumentRoot /media/myserver/ Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all 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
然后应该给出适当的许可,如下所示:
sudo adduser www-data sudo chown -R www-data:www-data /media/myserver/ sudo chmod -R g+rw /media/myserver/
sudo gedit etc/apache2/apache2.conf
添加此选项索引FollowSymLinks MultiViews AllowOverride无订单允许,拒绝允许所有
在虚拟配置中: /etc/apache2/sites-available/site.conf
ServerAdmin anilrmg@localhost.com ServerName anilrmg.localhost.com ServerAlias www.anilrmg.localhost.com DocumentRoot /home/anilrmg/projects/code/anilrmg
sudo a2dissite 000-default.conf
对于那些使用VirtualBox guest添加的you don't have permission to access /on this server
尽管有上述所有内容,但you don't have permission to access /on this server
上:
如果您尝试将Apache文档根文件夹设置为VirtualBox共享文件夹,并且您已经尝试了上述所有内容并且没有帮助,那么还有一个步骤。
简而言之,解决方案是将用户’www-data’添加到’vboxsf’组:
sudo usermod -a -G vboxsf www-data
您无法更改VirtualBox共享文件夹的所有者和/或组,但上面的解决方案对我来说效果很好。
作为一种快速解决方法(安全快速),您可以将外部硬盘驱动程序的安装点设置为默认的根目录(默认情况下为/ var / www)。
将安装点分配给每个现有目录是安全的,但除非您卸载了驱动程序,否则无法访问旧内容。
要了解有关如何创建安装点的更多信息,请参阅此处。