1.創(chuàng)建nginx目錄
mkdir nginx
cd nginx
2.創(chuàng)建"Dockerfile"文件
touch Dockerfile
vim Dockerfile
FROM nginx
MAINTAINER nginx nginx@user.com.cn
ENV TZ Asia/Shanghai
# RUN apk add --no-cache tzdata \
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
# CMD cd / | mkdir data
# ENV TZ Asia/Shanghai
# RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
EXPOSE 80
3.創(chuàng)建"rebuild.sh"構(gòu)建腳本
touch rebuild.sh
chmod 777 rebuild.sh
vim rebuild.sh
docker stop docker-nginx
docker rm docker-nginx
docker rmi docker-nginx
docker build -t docker-nginx .
docker run -d -p 80:80 -v /root/docker/nginx/conf.d:/etc/nginx/conf.d/ -v /root/docker/nginx/html:/usr/share/nginx/html/ --name docker-nginx docker-nginx
4.創(chuàng)建"conf.d"目錄
mkdir conf.d
5.創(chuàng)建"html"目錄
mkdir html
6.創(chuàng)建"default.conf"配置文件
cd conf.d
touch default.conf
vim default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html/service;
index index.html index.htm;
}
location /service {
proxy_pass http://ip:port/service;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 3;
gzip_types text/plain text/css application/xml application/javascript application/x-javascript text/javascript;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
7.啟動nginx
bash /root/docker/nginx/rebuild.sh