docker creates nginx container and configuration file mount statement record
pull nginx command
docker pull nginx
Ordinary command to create a container and mount a configuration file
- The html folder is for accessing page static resources, the conf.d folder is for subfiles of nginx configuration, and the nginx.conf file configuration file entry *
docker run --name nginx -p80:80 -v /etc/nginx/conf.d:/etc/nginx/conf.d -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/html:/usr/share/nginx/html -d nginx
Create a container and mount the configuration file command when configuring the ssl certificate
- Mount one more folder for the certificate *
docker run --name nginx -p80:80 -p443:443 -v /etc/nginx/conf.d:/etc/nginx/conf.d -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/html:/usr/share/nginx/html -v /etc/nginx/cert:/etc/nginx/cert -d nginx
The configuration file configures the ssl certificate
- There are two nginx configuration files, nginx.conf and default.conf. The content of default.conf is introduced into nginx.conf, we only need to modify the content of default.conf *
server {
listen 80; #http默认访问端口
listen 443 ssl; #https默认访问端口
server_name 域名;
# 注意证书文件位置,是从/etc/nginx/下开始算起的
ssl_certificate cert/7796667_域名.pem;
ssl_certificate_key cert/7796667_域名.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}