第二十一章 Centos7下Docker安裝Nginx
阿新 • • 發佈:2021-12-24
一、查詢Nginx映象
[root@staging ~]# docker search nginx
二、拉取Nginx映象
[root@staging ~]# docker pull nginx
三、執行Nginx
[root@staging ~]# docker run \ -itd \ -p 8080:80 \ -v /data2/nginx/html:/usr/share/nginx/html \ -v /data2/nginx/logs:/var/log/nginx \ -v /data2/nginx/nginx.conf:/etc/nginx/nginx.conf \ -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \ --restart always \ --privileged=true \ --name nginx \ nginx
四、編寫Nginx配置檔案
[root@staging ~]# vim nginx.conf user root; worker_processes auto; worker_cpu_affinity auto; error_log /var/log/nginx/error.log warn; pid /run/nginx.pid; worker_rlimit_nofile 35535; events { use epoll; worker_connections 10240; } http { include mime.types; default_type application/octet-stream; charset utf-8; 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; server_tokens off; client_max_body_size 200m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; gzip on; gzip_disable "MSIE [1-6]\."; gzip_http_version 1.1; gzip_comp_level 2; gzip_buffers 16 8k; gzip_min_length 1024; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg; include /etc/nginx/conf.d/*.conf; }
五、編寫Nginx的html檔案
[root@staging ~]# cd /data2/nginx/html/
[root@staging test]# echo "wo shi dashuaige" > test.html