Docker筆記-建立nginx並設定外掛資料夾
docker 快速啟動nginx
1.創出要與container連結的資料夾
mkdir /docker-lab
mkdir /docker-lab/nginx
mkdir /docker-lab/nginx/conf
mkdir /docker-lab/nginx/conf/vhost
mkdir /docker-lab/nginx/log
mkdir /docker-lab/nginx/html
2.創立nginx的設定檔,包含nignx.conf與vhost裡面的*.conf
nginx.conf
===========================================================
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
===========================================================
*.conf
===========================================================
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/test.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
===========================================================
2.啟動nginx的container並將設定檔位置、log位置、網頁位置連結到剛剛創立的資料夾內
docker run --name nginx \
-p 8080:80 \
-v /docker-lab/nginx/conf/nginx.conf:/etc/nginx/nginx/conf \
-v /docker-lab/nginx/conf/vhost/:/etc/nginx/conf.d \
-v /docker-lab/nginx/html/:/usr/share/nginx/html \
-v /docker-lab/nginx/log/:/var/log/nginx \
-d nginx
留言
張貼留言