目录
前言
Nginx是用来做Http和反向代理
介绍
建议现在服务器上先装一个nginx,这样一些nginx基本文件就都有了,然后基于ubuntu的镜像打nginx镜像
制作
1、在/etc/nginx文件夹下新增Dockerfile文件
FROM ubuntu:18.04
# Create app directory
WORKDIR /etc/nginx
RUN apt-get update
RUN apt-get install -y nginx
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . /etc/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2、运行镜像制作脚本
docker build -t imagenginx:v4 .
运行结果
3、至此,一个调度中心镜像就制作完毕了,接下来我们运行这个镜像。
由于nginx需要代理多个端口,需要把所有相关的端口都映射出来。
docker run --name dockernginxv4 -p 10083:10083 -p 10051:10051 -p 10054:10054 -p 10080:10080 -p 10060:10060 -p 10070:10070 -d imagenginx:v4
运行结果
--以下废弃
以下是我们自己项目的nginx.conf配置项
1、先下载一个nginx镜像
$ docker pull nginx:latest
2、基于nginx镜像运行一个容器
$ docker run --name <dockername> -p 10083:10083 -p 10051:10051 -d <iamgename>
3、进入容器,编辑nginx配置文件
3.1、先安装一下vim(当然你也可以在外面编辑好了拷贝进来,我自己实验就直接在容器中编辑了)
3.2、产品的原始config文件
#user www-data;
user root;
worker_processes auto;
worker_rlimit_nofile 65535;
pid /run/nginx.pid;
events {
use epoll;
worker_connections 65535;
multi_accept on;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
underscores_in_headers on;
client_max_body_size 100m;
client_header_buffer_size 4k;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/conf.d/boost/*.conf;
include /etc/nginx/conf.d/boost-demo/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
有一部分要替换成容器独有的语法,改完后为:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 65535;
multi_accept on;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
underscores_in_headers on;
client_max_body_size 100m;
client_header_buffer_size 4k;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/conf.d/boost/*.conf;
include /etc/nginx/conf.d/boost-demo/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
4、配置各个web、webapi的配置文件
相关错误截图:
本地配置nginx文件