- 安装nginx ,输入指令
apk add nginx
/usr/sbin # apk add nginx
WARNING: Ignoring //mirrors.aliyun.com/alpine/edge/community/x86_64/APKINDEX.tar.gz: No such file or directory
fetch http://mirrors.aliyun.com/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.aliyun.com/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/2) Installing pcre (8.42-r2)
(2/2) Installing nginx (1.14.2-r5)
Executing nginx-1.14.2-r5.pre-install
Executing busybox-1.29.3-r10.trigger
OK: 87 MiB in 59 packages
/usr/sbin #
- 配置用户,通过apk直接安装的nginx配置中默认用户是nginx,省事可以直接改成当前用户,不过建议还是创建一个新用户:
# 创建www用户
/usr/sbin # adduser -D -g 'nginx' nginx
# 配置权限
/usr/sbin # chown -R nginx:nginx /var/lib/nginx
# 备份配置文件
/usr/sbin # cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
# 配置启动目录
/usr/sbin # mkdir -p /run/nginx/
如果要改nginx运行用户,打开 /etc/nginx/nginx.conf
,找到user节点修改:
# /etc/nginx/nginx.conf
user root;
- 运行nginx
如果已经在容器环境中,直接输入 nginx 命令运行
/usr/sbin # nginx
/usr/sbin #
如果是要创建一个nginx镜像,ENTRYPOINT的命令要带上 daemon off
,避免nginx后台运行后主进程1结束导致容器直接关闭:
CMD ["nginx", "-g", "daemon off;"]