查看可用的 Nginx 版本
访问 Nginx 镜像库地址: https://hub.docker.com/_/nginx?tab=tags。
可以通过 Sort by 查看其他版本的 Nginx,默认是最新版本 nginx:latest。
此外,我们还可以用 docker search nginx 命令来查看可用版本:
script1 2 3 4 5 6 7 8
| $ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 3260 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 674 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 207 [OK] million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS... 67 [OK] maxexcloo/nginx-php Docker framework container with Nginx and ... 57 [OK] ...
|
取最新版的 Nginx 镜像
script1
| docker pull nginx:latest
|
正式安装
在宿主机中创建挂载目录
我原来目录已经有了 /data/blog/public /data/blog/static
加密上也有了 /htpasswd/passwd.db
script1
| mkdir -p /data/blog/nginx/{conf,log}
|
将配置文件放到挂载目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| user www-data; worker_processes auto; pid /run/nginx.pid;
events { worker_connections 768; # multi_accept on; }
http {
## # Basic Settings ##
sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off;
# 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/sites-enabled/*;
server{ listen 80; server_name anarckk.best; #你的serverName
location / { root /usr/share/nginx/html; index index.html; } location ^~ /static/ { root /usr/share/nginx/; } } }
|
启动容器
script1
| docker run --name blog -d -p 4399:80 -v /data/blog/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/blog/nginx/log:/var/log/nginx -v /data/blog/public:/usr/share/nginx/html -v /data/blog/static:/usr/share/nginx/static -v /htpasswd/passwd.db:/usr/share/nginx/passwd.db nginx:latest
|
参考链接
https://www.runoob.com/docker/docker-install-nginx.html
https://www.cnblogs.com/javafucker/p/10033589.html