docker-nginx

宿主机创建目录
/apnode/data/webroot,
/apnode/data/weblogs,
/apnode/data/nginx.conf

docker nginx 配置文件


####################################	
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") { set $year $1; set $month $2; set $day $3; }
####################################	
access_log ./web_log/temphost.access.$year-$month-$day.log format_main;  		
error_log  ./web_log/temphost.error.log;
####################################

worker_processes 1;
events {
	worker_connections 1024;
}
http {
	include mime.types;
	default_type application/octet-stream;
	sendfile on;
	#tcp_nopush on;
	#keepalive_timeout 0;
	keepalive_timeout 65;
	#gzip on;
	server {
		listen 80;
		# 绑定主机名 [localhost]。
		server_name localhost;
		#root目录
		root /apnode/data/webroot;
		#关闭 favicon.ico 日志
		location = /favicon.ico { access_log off; log_not_found off; }
		# 客户端Body大小限制(文件上传大小限制配置)
		client_max_body_size 50m;
		# 指定字符集为 UTF-8
		charset utf-8;
		# Vue路由模式为history需添加的配置
		location / {
		# root /apnode/data/webroot;
		index index.html index.php;
		# 默认文件搜索顺序
		try_files $uri $uri/ /index.php?$query_string;
		}
		# 获取真实IP以及Websocket需添加的配置
		# proxy_set_header 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;
		# proxy_set_header Upgrade $http_upgrade;
		# proxy_set_header Connection "upgrade";
		# error_page 500 502 503 504 404 /50x.html;
		# location = /50x.html {
		# root html;
		# }
		# 将 [404] 错误交给 [/index.php] 处理,表示由 Laravel 渲染美观的错误页面。
		error_page 404 /index.php;		
		#php环境安装完毕之后开启这段配置
		location ~ \.php$ {
		# 注意这里的IP和端口,用Docker实例IP端口默认应为9000,可选sock
		fastcgi_pass 192.168.56.2:9003;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		#fastcgi_param SCRIPT_FILENAME /apnode/data/webroot/$fastcgi_script_name;
		include fastcgi_params;
		}
		# 除符合正则表达式 [/\.(?!well-known).*] 之外的 URI,全部拒绝访问
		# 也就是说,拒绝公开以 [.] 开头的目录,[.well-known] 除外
		location ~ /\.(?!well-known).* {
			deny all;
		}
			
	}
}

获取所有容器IP,fastcgi_pass 可选对应IP
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)

docker 运行nginx
docker run -it -d --name vbox-nginx -p 80:80 -v /apnode/data/nginx.conf:/etc/nginx/nginx.conf -v /apnode/data:/apnode/data nginx:stable-alpine

###
$time_iso8601 生成格式:2013-09-25T15:16:35+08:00
$time_local 生成格式: 25/Sep/2013:15:12:13 +0800