这就是我要完成的任务:创建符号链接var/www/html
到home(~
)文件夹中的目录.我试图在home(~
)中符号链接的目录是一个git存储库,如果这有任何区别.我在这个目录中有一个index.html文件.
我使用此命令在Amazon EC2实例上创建了一个指向var/www/html的符号链接:ln -s ~/dirIWant/ html
但是当我尝试访问我的网页时,这会导致以下错误:403 Forbidden "You don't have permission to access / on this server."
我正在使用apache.
有没有其他人试图做类似的事情并让它工作?
目前,当我访问我的网站www.blah.com时,它显示403错误.我试图改变使用权限,sudo chown -h apache:apache
但它似乎没有帮助.你还有其他建议吗?
这是因为apache作为apache用户运行,并且/var/www/html
由Amazon Linux AMI中的root拥有.您可以按照Frank的建议更改所有权/权限,也可以使用userdirs.
在我看来,您希望可以从主目录(~
)方便地访问Web服务器的文件夹.我在EC2上想要这样的东西,并决定使用Per-user web目录(mod_userdir).
此功能允许您将HTTP服务器空间的一部分保留在用户拥有的目录中.每个用户都有自己的目录,默认位于/home/username/public_html
.通过附加/~username
到您的域,可以访问该目录中的页面,脚本和其他文件.此外,您可以将httpd.conf中该文件夹的名称更改为其他名称public_html
,例如gitRepo
.在这种情况下,如果您有一个index.html
文件/home/ec2-user/gitRepo/index.html
,它将由公众访问http://ec2-hostname.aws.amazon.com/~ec2-user/index.html
并由ec2-user拥有,这便于从用户级编辑文件.
要在EC2上进行设置(假设您要使用的文件夹名称为"gitRepo"),请使用nano /etc/httpd/conf/httpd.conf
打开Apache配置文件并向下滚动直至看到<IfModule mod_userdir.c>
.然后将此部分更改为如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
之后你应该好好去,但要确保正确设置权限:
chmod 711 /home/ec2-user
chmod 755 /home/ec2-user/gitRepo
chown -R ec2-user /home/ec2-user/gitRepo
Run Code Online (Sandbox Code Playgroud)
最后像这样重新加载Web服务器:
sudo service httpd reload
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16712 次 |
最近记录: |