如何在 Ubuntu 中创建公共 HTML 文件夹?
简单的问题,但由于某种原因我无法在 Google 上找到确切的答案:
我在 Slicehost 上安装了全新的 Ubuntu,并且想在我的主目录中为包含一堆静态 HTML 文件的简单网站创建一个公共目录。 我该怎么做呢? 这只是输入 mkdir public_html
并设置权限的问题,还是有更干净的方法? (我记得过去我遇到过这样的问题:每次将文件复制到 public_html 目录中时,我都必须手动设置其权限,这非常令人沮丧。)
Simple question, but for some reason I couldn't find the exact answer on Google:
I have a fresh Ubuntu install on Slicehost, and would like to make a public directory in my home dir for a simple website containing a bunch of static HTML files. How do I do this? Is it just a matter of typing mkdir public_html
and setting the permissions, or is there a cleaner way? (I remember in the past I've had issues where every time I copied a file into my public_html directory, I would have to manually set its permissions, which was quite frustrating.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您已经安装了 apache,请执行以下操作:
第一个命令启用 userdir apache mod,它正是您想要的。 第二个重新加载 apache 配置,以便它开始使用新配置。
要安装 apache2:
当然,您还需要确保 public_html 文件夹的权限允许 www-data 用户查看其中的文件 - 755 通常效果很好。 为此:
这将递归地 (-R) 遍历您的 public_html 并将权限设置为 755(所有者 rwx,以及组和其他 rx、rx)。
Assuming you've already installed apache, do the following:
The first command enables the userdir apache mod, which does exactly what you want. The second reloads apache configurations so that it starts using the new configuration.
To install apache2:
Of course, you'll also need to make sure that the permissions on your public_html folder allow the www-data user to see the files in there -- 755 usually works well. To do this:
This will recursively (-R) go through your public_html and set the permissions to 755 (owner rwx, and both group and other r-x, r-x).
其他答案都在
mod_userdir
的正确轨道上,但使用它将为您的网站提供基本 URLhttp://www.yourdomain.com/~username/
- 用于例如,文件/home/username/public_html/index.html
可以通过http://www.yourdomain.com/~username/index.html
访问。 如果您希望您的文件可以在域根下访问,例如http://www.yourdomain.com/index.html
,那么您需要将该指令放入Apache 配置中文件。
The other answers are on the right track with
mod_userdir
, but using that will give your website the base URLhttp://www.yourdomain.com/~username/
- for instance, a file/home/username/public_html/index.html
would be accessible ashttp://www.yourdomain.com/~username/index.html
. If you want your files to be accessible under the domain root, ashttp://www.yourdomain.com/index.html
for example, then you'll need to put the directivein the Apache configuration file.
Apache需要使用mod_userdir,否则需要设置来自
/var/www/
或任何地方的符号链接。您的权限问题是因为 Apache 没有对您的文件的读取权限。 您需要允许对
www-data
进行读取访问(或任何用户;特定于发行版)。You need to use mod_userdir for Apache, otherwise you need to set up symlinks from
/var/www/
or wherever.Your permissions issue is because Apache does not have read access to your files. You need to allow read access to
www-data
(or whatever the user is; distro-specific).