docker安装nginx,配置多个域名

2020-10-29 77点热度 1人点赞

1.查询获取nginx镜像

docker search nginx

2.下载nginx镜像

docker pull nginx

3.创建并启动容器

docker run -p 80:80 --name mynginx -v /nginx/nginx.conf:/etc/nginx/nginx.conf -d nginx

创建了一个名字为nginx的容器,文件默认存在/etc/nginx/nginx.conf中,也可以拷贝到/nginx/nginx.conf中

4.进入/nginx/nginx.conf中修改配置

http { 

  server {
    listen 80; 
    server_name yxiumei.com; 
    access_log off;
    
    location / { 
    proxy_pass a.com:9000; 
    proxy_read_timeout 300;
    proxy_connect_timeout 300;
    proxy_redirect     off;
    
    proxy_set_header   X-Real_IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    }
  }

}

  server {
    listen 80; 
    server_name abc.com; 
    access_log off;
    
    location / { 
      proxy_pass http://abc.com:8000; 
      proxy_read_timeout 300;
      proxy_connect_timeout 300;
      proxy_redirect     off;
    
      proxy_set_header   X-Real_IP $remote_addr;
      proxy_set_header   Host      $http_host;
      proxy_set_header   X-Real-IP         $remote_addr;
    }
     
  }
} 

5.修改配置文件需要重启,进etc/nginx目录执行

nginx -s reload

未经允许不得转载!docker安装nginx,配置多个域名

本文地址:https://ai.52learn.online/1844

站长邮箱:ai52learn@foxmail.com