如何更改apache服务器的根目录? [英] How do I change the root directory of an apache server?
问题描述
有人知道如何更改Apache服务器的文档根目录吗?我基本上希望localhost
来自/users/spencer/projects
目录而不是/var/www
.
Does anyone know how to change the document root of the Apache server? I basically want localhost
to come from /users/spencer/projects
directory instead of /var/www
.
我最终弄清楚了.有人建议我更改httpd.conf
文件,但最终在/etc/apache2/sites-available/default
中找到一个文件,并将根目录从/var/www
更改为/home/myusername/projects_folder
,并且可以正常工作.
I ended up figuring it out. Some suggested I change the httpd.conf
file, but I ended up finding a file in /etc/apache2/sites-available/default
and changed the root directory from /var/www
to /home/myusername/projects_folder
and that worked.
推荐答案
您需要在httpd.conf
文件中更改DocumentRoot
设置.可能会出现在/etc/apache2/conf/httpd.conf
You need to change the DocumentRoot
setting in your httpd.conf
file. Chances are it will be under something like /etc/apache2/conf/httpd.conf
使用您喜欢的编辑器(我建议 Vim )并找到DocumentRoot
并将其更改为/users/spencer/projects
.对于看起来像这样的设置,还往下看一点:
Use your favourite editor (I recommend Vim) and look for the DocumentRoot
and change it to /users/spencer/projects
. Also look a little further down for a setting that looks like this:
<Directory "/var/www">
您还希望将引号中的内容更改为新目录.这样,当用户发出调用该目录的请求时,Apache便可以从该目录进行读取.
You will also want to change what is in the quotes to your new directory. This gives Apache access to read from that directory when a user makes a request that call on it.
现在重新启动apache服务(httpd -k restart
),您应该会很好.
Now restart your apache service (httpd -k restart
) and you should be good to go.
编辑:Apache2站点配置文件现在通常保存在/etc/apache2/sites-available/
(Debian,Ubuntu等)中.
Edit: Apache2 site config files are now typically kept in /etc/apache2/sites-available/
(Debian, Ubuntu, etc.).
这篇关于如何更改apache服务器的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!