我正在尝试将 ec2 配置为我的 Web 服务器,以便在负载均衡器下进行扩展,但正如 httpd.conf 注释所说,
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache
标准 Amazon Linux RMI 的默认用户和组是 apache。我想将其更改为我创建的用户和组,例如 my-user。
如您所知,ec2 的 User/Data 部分可以包含一个 bash 脚本,该脚本将在配置 ec2 时执行操作。我有:
#!/bin/bash
yum install httpd24 mysql57 php71 php71-mysql\* -y
安装 httpd 后,是否可以使用 CLI 命令从此 bash 脚本更改 httpd 用户和组 - 或者使用 httpd.conf 中的环境变量?
答案1
最后,我发现这对我有用:
# configure the httpd web server daemon to run as user ddfs
touch /etc/httpd/conf.d/ddfs.conf
chmod 777 /etc/httpd/conf.d/ddfs.conf
cat <<EOF > /etc/httpd/conf.d/ddfs.conf
User ddfs
Group ddfs
EOF
chmod 644 /etc/httpd/conf.d/ddfs.conf
# start the web server daemon
service httpd start
# Set the server config so that httpd automatically gets started when the server is booted
chkconfig httpd on