Docker安装nginx

创建目录:

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;
  }
}

重启nginx:

docker restart nginx

 

©️2020 CSDN 皮肤主题: 程序猿惹谁了 设计师:上身试试 返回首页