尝试对 var/www/html 使用符号链接 [英] Attempting to use symbolic link for var/www/html

查看:16
本文介绍了尝试对 var/www/html 使用符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要完成的:创建从 var/www/html 到 home (~) 文件夹中的目录的符号链接.我试图符号链接到的目录 (~) 是一个 git 存储库,如果这有什么不同的话.我在这个目录中有一个 index.html 文件.

this is what I'm trying to accomplish: creating symbolic link from var/www/html to a directory in the home (~) folder. the directory I'm trying to symlink to in home (~) is a git repository, if that makes any difference. I have an index.html file in this directory.

我已经使用以下命令在 Amazon EC2 实例上创建了一个指向 var/www/html 的符号链接:ln -s ~/dirIWant/html,但是这会导致以下错误我尝试访问我的网页:403 Forbidden 您无权访问/在此服务器上." 我正在使用 apache.

I've created a symbolic link to var/www/html on an Amazon EC2 instance using this command: ln -s ~/dirIWant/ html, however this is resulting in the following error when I try to access my webpage: 403 Forbidden "You don't have permission to access / on this server." I'm using apache.

有没有其他人尝试过做类似的事情并让它发挥作用?

Has anybody else tried to do something similar and gotten it to work?

目前,当我访问我的网站 www.blah.com 时,它会显示此 403 错误.我尝试使用 sudo chown -h apache:apache 更改权限,但似乎没有帮助.您还有其他想法吗?

Currently, when I go to my website www.blah.com, it shows this 403 error. I've tried to change the permission using sudo chown -h apache:apache but it doesn't seem to help. Do you have any other ideas?

推荐答案

这是因为 apache 以 apache 用户身份运行,并且 /var/www/html 由根在 Amazon Linux AMI 中.您可以按照 Frank 的建议更改所有权/权限,或使用 userdirs.

This is because apache runs as apache user and the /var/www/html is owned by root in Amazon Linux AMI. You can change ownership/permissions as suggested by Frank, or use userdirs.

在我看来,您希望可以从您的主目录 (~) 方便地访问网络服务器的文件夹.我想在我的 EC2 上使用类似的东西,并决定使用 每用户 Web 目录 (mod_userdir).

It seems to me that you want the webserver's folder to be conveniently accessible from your home directory (~). I wanted something like this on my EC2 and decided to use Per-user web directories (mod_userdir).

此功能允许您将部分 HTTP 服务器空间保留在用户拥有的目录中.每个用户都有自己的目录,默认位于 /home/username/public_html.通过将 /~username 附加到您的域,互联网可以访问该目录中的页面、脚本和其他文件.此外,您可以将 httpd.conf 中该文件夹的名称从 public_html 更改为其他名称,例如 gitRepo.在这种情况下,如果您在 /home/ec2-user/gitRepo/index.html 中有一个 index.html 文件,则公众可以通过 http://ec2-hostname.aws.amazon.com/~ec2-user/index.html 并且归ec2-user所有,方便用户级编辑文件.

This feature of lets you keep parts of the HTTP server's space in a directory owned by a user. Each user gets his own directory, located by default in /home/username/public_html. The pages, scripts and other files in that directory are accessible to the internet by appending /~username to your domain. Additionally, you can change the name of that folder in httpd.conf from public_html to something else, like gitRepo. In that case, if you have an index.html file in /home/ec2-user/gitRepo/index.html, it will be accessible to the public via http://ec2-hostname.aws.amazon.com/~ec2-user/index.html and be owned by ec2-user, which is convenient for editing files from user level.

要在 EC2 上进行设置(假设要使用的文件夹名称为gitRepo"),请使用 nano/etc/httpd/conf/httpd.conf 打开 Apache 配置文件并滚动直到您看到 .然后将此部分更改为如下所示:

To set this up on EC2 (assuming "gitRepo" for the folder name you want to use), use nano /etc/httpd/conf/httpd.conf to open Apache config file and scroll down until you see <IfModule mod_userdir.c>. Then change this section to look like the following:

<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir enabled all

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    #
    UserDir gitRepo

</IfModule>

之后你应该很高兴,但要确保权限设置正确:

Afterwards you should be good to go but ensure the permissions are set up correctly:

chmod 711 /home/ec2-user
chmod 755 /home/ec2-user/gitRepo
chown -R ec2-user /home/ec2-user/gitRepo

最后像这样重新加载网络服务器:

And finally reload the web server like this:

sudo service httpd reload

这篇关于尝试对 var/www/html 使用符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆