nginx-host

 下载nginx镜像

docker pull docker.io/nginx:latest

  

由于calico网络不支持http协议,所以即使你在iptables中配置了nat路由,将访问宿主机80端口的请求都转发到nginx-consul-template,外部也无法访问nginx-ingress。于是我们需要额外启动一个nginx(docker host网络),来做反向代理到nginx-ingress。
另如果你需要不同网卡下面的网络通讯的话,你只需要在iptables中添加NAT条目即可:

配置nginx

mkdir -p /opt/platform/nginx-host && cd /opt/platform/nginx-host && mkdir -p conf/conf.d modules html logs
vim /opt/platform/nginx-host/conf/conf.d/default.conf
upstream nginx-calico {
    server 10.233.2.1:80;
	server 10.233.3.1:80;
	server 10.233.4.1:80;
}
server {
    listen 80;
    charset utf-8;
    server_name *.test.com;
    location / {
        proxy_pass http://nginx-calico;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 10s;
        proxy_send_timeout 150s;
        proxy_read_timeout 150s;
        proxy_next_upstream error timeout invalid_header http_404 http_502 http_504 http_500;
    }
}

上传nginx.conf文件到/opt/platform/nginx-host/conf

#user  ops;
worker_processes  auto;
worker_cpu_affinity auto;

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

worker_rlimit_nofile 65535;

events {
	use epoll;
    worker_connections  65535;
}


http {
    include       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"';

	log_format  json  '{"@timestamp":"$time_iso8601",'
                      '"remote_addr":"$remote_addr",'
                      '"remote_user":"$remote_user",'
                      '"http_host":"$http_host",'
                      '"request":"$request",'
                      '"status":"$status",'
                      '"body_bytes_sent":$body_bytes_sent,'
                      '"http_referer":"$http_referer",'
                      '"http_user_agent":"$http_user_agent",'
                      '"http_x_frowarded_for":"$http_x_forwarded_for",'
   		      '"upstream_status":"$upstream_status",'
                      '"upstream_addr":"$upstream_addr",'
                      '"upstream_response_time":"$upstream_response_time",'
                      '"request_time":$request_time}';


    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    client_header_buffer_size    20m;
    large_client_header_buffers  4 2048k;
    client_max_body_size 20m;
    proxy_buffer_size 64k;
    proxy_buffers   4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    proxy_ignore_client_abort  on;  #让代理服务端不要主动关闭客户端的连接。

    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png application/javascript;
    gzip_proxied any;
    gzip_disable "MSIE [1-6].";

server {
        listen 80 default;
        server_name _;
        return 499;
        }

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

以及上传mime.types文件到/opt/platform/nginx-host/conf

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    application/font-woff                            woff;
    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}

  

 

运行nginx-host

docker run -d 
--net=host 
-v /opt/platform/nginx-host/conf:/etc/nginx 
-v /opt/platform/nginx-host/modules:/usr/lib/nginx/modules 
-v /opt/platform/nginx-host/html:/usr/share/nginx/html 
-v /opt/platform/nginx-host/logs:/var/log/nginx 
--name=nginx-host nginx

  

原文地址:https://www.cnblogs.com/cjsblogs/p/9176658.html