1. 程式人生 > >docker(五):Mac docker 自定義nginx配置打包nginx映象

docker(五):Mac docker 自定義nginx配置打包nginx映象

1.基於映象庫的nginx再修改nginx配置,編寫Dockerfile

from hub.c.163.com/library/nginx:latest
MAINTAINER Jinx----
COPY default.conf /etc/nginx/conf.d/default.conf
COPY proxy.conf /etc/nginx/proxy.conf
COPY nginx.conf /etc/nginx/nginx.conf

進入一個指定的掛載目錄
需要複製的檔案必須在該目錄下
proxy.conf是我自己加的內容如下:

proxy_set_header        Host $host
; proxy_set_header X-Real-IP $remote_addr;

初始映象下的nginx.conf內容如下:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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
65; #gzip on; include /etc/nginx/conf.d/*.conf; }

我修改的內容如下:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 1024;
events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    include       proxy.conf;
    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;


    server_tokens off;
    sendfile        on;
    tcp_nopush     on;
    server_names_hash_bucket_size 256;
    client_header_buffer_size 256k;

    large_client_header_buffers 4 256k;
    client_body_buffer_size 256k;
    client_header_timeout     3m;
    client_body_timeout 3m;
    send_timeout             3m;

    client_max_body_size 50m;
    keepalive_timeout  120;
    fastcgi_intercept_errors on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;

    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;
}

關於default.conf就是基本的代理內容,具體如下:

server {

    listen       80;
    server_name  app.xx.com;

    location /{
            proxy_pass    http://139.196.15.xx:8080;
    }

    location /gtw {
            proxy_pass    http://139.196.15.xx:8020;
    }

    location /protops-admin {
        proxy_pass http://139.196.15.xx:8010;
    }
   location /vihicle_uploads {
        proxy_pass http://139.196.15.xx:8030;
    }   
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

2.cd到該目錄下打包映象:(具體解釋參照上一篇)

docker build -t xx-nginx:latest .

3.啟動應用,建立服務

docker run -d -p 900:80 映象ID