::: warning 注意
服务器保证可以正常连接访问,国内的已备案,并开放了端口
:::
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
docker -v
docker pull nginx:latest
docker run --name temp-nginx 8080:80 -d nginx
docker images
查看是否下载成功,没有则重新下载docker logs temp-nginx
查看错误日志信息mkdir -p /docker/nginx
/docker/nginx
目录下
docker cp temp-nginx:/etc/nginx/nginx.conf /docker/nginx
docker cp -a temp-nginx:/usr/share/nginx/html /docker/nginx
docker rm -f temp-nginx
vi /docker/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;
这段话,不然他会引入 conf.d 里的配置
server
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
sendfile on;
keepalive_timeout 65;
# 注释下面这段,不然他会引入conf.d里的配置
# include /etc/nginx/conf.d/*.conf;
# 文件里面所有的路径都要写容器里的路径,不要写本地路径,不然会找不到文件
# 所以后面会把本地路径映射到容器路径
# 比如 /usr/share/nginx/html 其实会访问 /docker/nginx/html 目录
# 开启服务
server {
listen 80;
server_name biaov.cn;
location / {
# vue文件存放目录
# 注意这里一定是容器路径,不能是本地路径
root /usr/share/nginx/html;
index index.html index.htm;
}
}
}
docker run -d --name nginx-http -p 80:80 -v /docker/nginx/html:/usr/share/nginx/html -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf nginx
::: tip 完成
部署完成
:::
server {
listen 443 ssl;
server_name biaov.cn;
ssl_certificate /etc/nginx/cert/biaov/biaov.cn.pem;
ssl_certificate_key /etc/nginx/cert/biaov/biaov.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
docker run -d --name nginx-https -p 443:443 -v /docker/nginx/html:/usr/share/nginx/html -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf /docker/nginx/certs:/etc/nginx/cert -v /docker/nginx/config:/etc/nginx/config nginx