使用Docker部署nginx+php

创建目录:

mkdir -p /home/docker/nginx/config/conf.d
mkdir -p /home/docker/nginx/html
mkdir -p /home/docker/nginx/logs

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

docker run --name tmp-nginx-container -d nginx
docker cp tmp-nginx-container:/etc/nginx/nginx.conf /home/docker/nginx/config/nginx.conf
docker cp tmp-nginx-container:/etc/nginx/conf.d/default.conf /home/docker/nginx/config/conf.d/default.conf
docker rm -f tmp-nginx-container

运行正式容器:

docker run -d --name nginx \
--restart=always \
-p 8080:80 \
-v /home/docker/nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro  \
-v /home/docker/nginx/config/conf.d:/etc/nginx/conf.d  \
-v /home/docker/nginx/html:/usr/share/nginx/html \
-v /home/docker/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

最后编辑于:2020/4/18作者: 编程小战

我不入地狱,谁入地狱?

评论已关闭