Kev*_*abu 40 server lamp apache2
我为我的服务器 pc 安装了 ubuntu 12.04 服务器版本。我已经安装了灯服务器。我需要将 var/www 位置更改为我的辅助硬盘位置。我在 gedit /etc/apache2/sites-available/default 这是我的代码
<VirtualHost *:80>
ServerAdmin webmaster@localhost
#DocumentRoot /var/www
DocumentRoot /media/myserver/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#<Directory /var/www/>
<Directory /media/myserver/>
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
Alias /doc/ "/usr/share/doc/"
<Directory "/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
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
并且还使用了
sudo chown -R var/www /media/myserver/
Run Code Online (Sandbox Code Playgroud)
和
chmod -R 755 /media/myserver/
Run Code Online (Sandbox Code Playgroud)
我仍然无法连接我的 /media/myserver 并且我的浏览器显示以下消息
Forbidden
You don't have permission to access / on this server.
Run Code Online (Sandbox Code Playgroud)
请告诉任何人如何在我的 var/www 上安装 myserver,提前感谢
小智 65
您必须编辑apache2.conf
和000-default.conf
更改 apache 的文档根目录。
Apache 服务器安装在/var/www/html
。这是 apache 的默认根目录。
更改 Apache 的根目录或将项目移动到/var/www/html
.
要更改 Apache 的根目录,请运行:
cd /etc/apache2/sites-available
Run Code Online (Sandbox Code Playgroud)
然后000-default.conf
使用以下命令打开文件:
nano 000-default.conf
Run Code Online (Sandbox Code Playgroud)
编辑DocumentRoot
选项:
DocumentRoot /path/to/my/project
Run Code Online (Sandbox Code Playgroud)
然后重启apache服务器:
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
如果您Forbidden You don't have permission to access / on this server
在更改 apache 的根目录后获得,请按照以下步骤操作
找到apache2.conf
位于/etc/apache2
并使用以下命令打开它:
nano apache2.conf
Run Code Online (Sandbox Code Playgroud)
使用Ctrl+W并搜索 Directory(应该在第 153 行)
它应该是这样的
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all denied
</Directory>
Run Code Online (Sandbox Code Playgroud)
将其更改为
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)
重启apache
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
我制作了一个脚本,可以在单个命令中更改 apache 根。你可以在我的github上找到它。
小智 23
也许有点晚了。但是还是..
您应该在 /etc/apache2 下的 apache.conf 中编辑您的目录权限
搜索这个
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)
并在其下添加此代码,这将授予访问您的目录的权限
<Directory /media/myserver/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)
只需更改激活配置中的文档根目录即可。/etc/apache2/sites-enabled/000-default
然后确保重新加载您的apache。
所以试试这个:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /media/myserver/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /media/myserver/>
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>
Run Code Online (Sandbox Code Playgroud)
然后应该像这样给予适当的许可:
sudo adduser <username> www-data
sudo chown -R www-data:www-data /media/myserver/
sudo chmod -R g+rw /media/myserver/
Run Code Online (Sandbox Code Playgroud)