如何更改 Apache 服务器的根目录? [英] How do I change the root directory of an Apache server?
问题描述
如何更改 Apache 服务器的文档根目录?我基本上希望 localhost
来自 /users/spencer/projects
目录而不是 /var/www
.
How can I 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.
Apache 2 站点配置文件现在通常保存在 /etc/apache2/sites-available/
(Debian、Ubuntu 等)中.
Apache 2 site configuration files are now typically kept in /etc/apache2/sites-available/
(Debian, Ubuntu, etc.).
这篇关于如何更改 Apache 服务器的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!