Docker安装Nginx(含:Windows启动、重启、停止)

Docker安装Nginx

#docker pull nginx:latest
(第一次启动Docker-Nginx)
#docker run --detach \
--publish 80:80 \
--restart always \
--volume /data/nginx/html:/usr/share/nginx/html:ro \
--volume /data/nginx/conf.d:/etc/nginx/conf.d:ro \
--volume /data/nginx/logs/:/var/log/nginx \
--volume /etc/localtime:/etc/localtime \
nginx:latest

停止Docker的Nginx

#docker stop ee6646198d59

删除Docker的Nginx容器

#docker rm ee6646198d59

修改nginx.conf文件

Docker安装Nginx(含:Windows启动、重启、停止)Docker安装Nginx(含:Windows启动、重启、停止)
user  nginx;
worker_processes 1; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections 1024;
} http { ##
# Basic Settings
## sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off; #关闭显示nginx版本 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;
# ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ciphers "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384:TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA:TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
# ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7 ##
# Log Settings
## 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; ##
# Gzip Settings
## gzip on;
gzip_vary on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_disable "msie6";
gzip_disable "MSIE [1-6].";
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript application/json;
##
# Proxy Headers
## include /etc/nginx/conf.d/*.conf; ##
# filter ip
##
include /etc/nginx/blocksip.conf; #过滤IP地址 ##
# Virtual Host Configs
## include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf; #配置各个站点的信息 }

nginx.conf

设置Nginx通过代理(proxy.conf)

# cat proxy.conf

proxy.conf文件内容

Docker安装Nginx(含:Windows启动、重启、停止)Docker安装Nginx(含:Windows启动、重启、停止)
proxy_redirect          off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

proxy.conf

某个站点的配置(gitlab.tidebuy.net)

# cat gitlab.aaa.conf 

gitlab.aaa.conf文件内容

server {
listen 80;
server_name gitlab.aaa.net;(按域名调度)
server_tokens off; access_log /var/log/nginx/gitlab_log.log; location / {
proxy_pass http://172.17.0.2; (Docker容器里面的IP地址)
}
}

Linux获取Docker容器里面IP地址

#docker inspect --format '{{ .NetworkSettings.IPAddress }}' 容器ID
#docker inspect 容器ID

Docker安装Nginx(含:Windows启动、重启、停止)

(第二次启动Docker-Nginx,增加nginx.conf文件)
#docker run --detach \
--publish 80:80 \
--restart always \
--volume /data/nginx/html:/usr/share/nginx/html:ro \
--volume /data/nginx/nginx.conf:/etc/nginx/nginx.conf \
--volume /data/nginx/conf.d:/etc/nginx/conf.d \
--volume /data/nginx/logs/:/var/log/nginx \
--volume /etc/localtime:/etc/localtime \
nginx:latest

重新启动Docker-Nginx容器

#docker restart 8611f472ebac

或者进入容器重新加载Nginx配置

#nginx -t && nginx -s reload

在Windows下操作nginx,需要打开 cmd 进入到nginx的安装目录下

1.启动nginx:

start nginx 或 nginx.exe

2.停止nginx(stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息)

nginx.exe -s stop          或         nginx.exe -s quit

3.检查

nginx -t     修改nginx配置后,执行检查配置是否正确

4.重启

nginx -s reload 重启
上一篇:蓝桥网试题 java 入门训练 A+B问题


下一篇:一步步教你搭建VS环境下用C#写WebDriver脚本