使用DockerCompose部署nginx

今天来记录一下使用DockerCompose部署nginx的简单过程。

首先我们需要有一个nginx.conf文件,内容如下:

user www-data;
worker_processes 4;
pid /run/nginx.pid;
#daemon off;

events {  }

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  gzip on;
  gzip_disable "msie6";
  include /etc/nginx/conf.d/*.conf;
  
  
  
  
  
  server {
        listen          0.0.0.0:80;
        server_name     _;

        root            /var/www/html/website;
        index           index.html index.htm;

        access_log      /var/log/nginx/default_access.log;
        error_log       /var/log/nginx/default_error.log;
	}

	#虚拟机器人
	server {
	   listen 19100;
	   server_name localhost;
	   client_max_body_size 1000M;


		location /robot/ {
			proxy_pass http://127.0.0.1:9100/;
		}
		
	   location / {
			proxy_set_header Host $host:$server_port;
			# 前端文件路径
			root   /home/web/dist;
			# index  index.html index.htm;
			if ( !-e $request_filename) {
				# 后端地址
				proxy_pass http://127.0.0.1:9100;
			}
			
		}
	}
}

具体内容根据自身情况进行修改。

docker-compose.yml文件

version: "3.0"
services:
    nginxServer:
        image: nginx
        container_name: nginx_server
        volumes:
            - /home/ubuntu2004/robot/web/nginx.conf:/etc/nginx/nginx.conf
            - /home/ubuntu2004/robot:/home
        #network_mode: host
        ports:
            - "19100:19100"
            - "19200:80"

搞定了!

ps:解压rar文件命令:unrar x 1009dist.rar

你可能感兴趣的:(Docker,#,Nginx,nginx,服务器,运维)