Docker安装Nginx(含:Windows启动、重启、停⽌)
Docker安装Nginx
#docker pull nginx:latest
(第⼀次启动Docker-Nginx)
#docker run --detach \
--publish 80:80 \
docker重启容器命令
--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
修改f⽂件
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/pes;
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:ECDH
E-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-GC    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/f;  #过滤IP地址
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;  #配置各个站点的信息
}
设置Nginx通过代理(f)
# f
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;
某个站点的配置(gitlab.tidebuy)
# cat f
f⽂件内容
server {
listen        80;
server_name  gitlab.aaa;(按域名调度)
server_tokens off;
access_log /var/log/nginx/gitlab_log.log;
location / {
proxy_pass 172.17.0.2; (Docker容器⾥⾯的IP地址)
}
}
Linux获取Docker容器⾥⾯IP地址
#docker inspect --format '{{ .NetworkSettings.IPAddress }}'容器ID
#docker inspect 容器ID
(第⼆次启动Docker-Nginx,增加f⽂件)
#docker run --detach \
--publish 80:80 \
--restart always \
-
-volume /data/nginx/html:/usr/share/nginx/html:ro \
--volume /data/f:/etc/f \
--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 或
2.停⽌nginx(stop是快速停⽌nginx,可能并不保存相关信息;quit是完整有序的停⽌nginx,并保存相关信息) -s stop          或        -s quit
3.检查
nginx -t    修改nginx配置后,执⾏检查配置是否正确
4.重启
nginx -s reload 重启

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。