Docker 简单搭建Nginx

2020-02-10  本文已影响0人  楚长铭

搭建环境

拉取镜像

docker  pull nginx

启动容器

docker run -d -p 20000:80 --name nginx-web -v /WorkSpace/dokcer/nginx/www:/usr/share/nginx/html -v /WorkSpace/dokcer/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /WorkSpace/dokcer/nginx/logs:/var/log/nginx nginx

配置文件


worker_processes  1;
 
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    sendfile        on;
    keepalive_timeout  65;

    charset utf-8;


    server{
        listen       80;
        server_name  localhost;
        
        location / {
           proxy_pass http://ip:端口号;

           proxy_set_header X-Forwarded-Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header REMOTE-HOST $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
    }

}

域名映射

server {
    listen       80;
    server_name  test.com;

    location / {
      proxy_pass http://ip:端口号;

      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
ip地址  www.test.com
上一篇下一篇

猜你喜欢

热点阅读