Loading
0

使用Docker部署nginx+php

设置环境变量:

DOCKER_VOLUME_HOME=/home/docker;

创建目录:

mkdir -p $DOCKER_VOLUME_HOME/nginx/config/conf.d
mkdir -p $DOCKER_VOLUME_HOME/nginx/html
mkdir -p $DOCKER_VOLUME_HOME/nginx/logs

运行临时容器,生成配置文件:

docker run --name tmp-nginx-container -d nginx

拷贝临时容器中的文件:

docker cp tmp-nginx-container:/etc/nginx/nginx.conf $DOCKER_VOLUME_HOME/nginx/config/nginx.conf;
docker cp tmp-nginx-container:/etc/nginx/conf.d/default.conf $DOCKER_VOLUME_HOME/nginx/config/conf.d/default.conf;
docker cp tmp-nginx-container:/usr/share/nginx/html $DOCKER_VOLUME_HOME/nginx;

删除临时容器:

docker rm -f tmp-nginx-container

运行正式容器:

docker run -d --name nginx \
--restart=always \
-p 8080:80 \
-v $DOCKER_VOLUME_HOME/nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro  \
-v $DOCKER_VOLUME_HOME/nginx/config/conf.d:/etc/nginx/conf.d  \
-v $DOCKER_VOLUME_HOME/nginx/html:/usr/share/nginx/html \
-v $DOCKER_VOLUME_HOME/nginx/logs:/var/log/nginx \
nginx

访问主机http的8080端口:

将子域名映射到指定的IP和端口,例如,在conf.d目录下增加sonarqube.conf文件:

upstream sonarqube
{
  server  35.220.133.116:9000;
}
 
server
{
  listen 80;
  server_name sonarqube.joycode.com.cn;
  location / 
  {
    proxy_pass http://sonarqube;
  }
}

重新加载配置:

docker exec nginx nginx -s reload

重启nginx:

docker restart nginx

参考:

https://blog.csdn.net/qq_21682469/article/details/102777738

最后编辑于:2021/3/24作者: 编程小战

我不入地狱,谁入地狱?

评论已关闭