amazon linux 用户名,使用Amazon Linux AMI在EC2上用于Web目录的Nginx用户帐户

作者在AmazonLinuxAMI上的Nginx配置中遇到问题,尝试更改服务器名称和站点目录所有权。他们发现只有当目录由root拥有时,网站才能访问,询问是否必须如此,以及是否应使用ec2-user或新创建的用户账户。
摘要由CSDN通过智能技术生成

我在Amazon Linux AMI上设置了Nginx . 默认的Nginx页面加载正常:

http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/

和nginx.conf中的服务器语句代码是:

server {

listen 80;

#server_name localhost;

server_name ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com;

#charset koi8-r;

#access_log /var/log/nginx/host.access.log main;

location / {

root /usr/share/nginx/html;

index index.html index.htm;

}

# redirect server error pages to the static page /40x.html

#

error_page 404 /404.html;

location = /40x.html {

root /usr/share/nginx/html;

}

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}

所以通过将server_name更改为我的域来测试它

server_name samplesite.com;

通过使用浏览器访问它也可以正常工作

http://samplesite.com/

但是当我将“location / root”更改为其他路径时,它不起作用,这里是nginx.conf服务器语句:

server {

listen 80;

server_name samplesite.com;

#charset koi8-r;

#access_log /var/log/nginx/host.access.log main;

location / {

root /home/ec2-user/samplesite.com/public_html;

index index.html index.htm;

}

# redirect server error pages to the static page /40x.html

#

error_page 404 /404.html;

location = /40x.html {

root /usr/share/nginx/html;

}

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}

唯一改变的部分是

root /home/ec2-user/samplesite.com/public_html;

这是因为我希望站点目录位于“ec2-user”下 . 我检查了默认的Nginx目录文件所有者

/usr/share/nginx/html

但是所有东西都归“root”所有,据我所知,不建议使用root帐户,并且应该使用不同的用户帐户:

drwxr-xr-x 2 root root 4096 Jan 22 01:14 .

drwxr-xr-x 3 root root 4096 Jan 22 01:14 ..

-rw-r--r-- 1 root root 3696 Nov 21 22:04 404.html

-rw-r--r-- 1 root root 3738 Nov 21 22:04 50x.html

-rw-r--r-- 1 root root 3770 Nov 21 22:04 index.html

-rw-r--r-- 1 root root 370 Nov 21 22:04 nginx-logo.png

所以想要使用"ec2-user"(或者我应该为网络创建一个新帐户?) . 所以我的问题是,该目录必须由"root"拥有才能工作吗?因为如果目录所有者在 /home/ 目录下是"ec2-user",我似乎无法访问该网站 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值