记录一下docker+nginx部署vue-element-admin
docker run -d -p 9528:80 --name nginx1
-v /usr/local/dormitory-web-admin/dist:/usr/share/nginx/html
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /usr/local/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
-v /usr/local/nginx/logs:/var/log/nginx nginx
###注意空格
###9528是项目端口号
- 第一个-v
/usr/local/dormitory-web-admin/dist:/usr/share/nginx/html
冒号前:/usr/local/dormitory-web-admin/dist代表vue-element-admin项目打包后生成的dist文件,目录根据项目的位置来,文件夹里面有static、favicon.ico、index.html
冒号后:docker容器nginx的html目录,固定值
- 第二个-v
/usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
冒号前:/usr/local/nginx/conf/nginx.conf代表nginx的主配置
冒号后:docker容器nginx的conf主配置目录,固定值
- 第三个-v
/usr/local/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
冒号前:/usr/local/nginx/conf/default.conf代表nginx的默认配置
冒号后:docker容器nginx的conf默认配置目录,固定值
- 第四个-v是日志
default.conf
server {
location / {
root /usr/share/nginx/html/;
index index.html;
try_files $uri $uri/ /index.html; #解决刷新页面404
}
}
nginx.conf
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;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
下面是目录的截图
前端项目文件