ECS 使用 Docker 部署静态网站为例
我购买的是腾讯云 ECS 服务器
系统盘:ubuntu
本次教程基于 01 手摸手带你使用Docker 部署静态网站(入门篇)
贴代码, 部署方式同 入门篇
- 创建
statci_app
文件夹,进入新建Dockerfile
# Dockerfile
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY website.conf /etc/nginx/conf.d/default.conf
COPY . /app/
- 新建
website.conf
文件
# website.conf
server {
listen 80;
server_name www.maopulas.com; # 修改为你自己的域名
root /app/;
location / {
try_files $uri $uri/ /index.html;
}
}
- 新建
nginx.conf
文件
# 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;
#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/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
}
- 新建
index.html
文件
<h1>hello Docker!</h1>
- 打包
static_app
文件夹为zip
格式,并且 copy 至服务器根目录
scp static_app.zip root@xxx.xxx.xxx.xx:~
- 解压
static_app.zip
,unzip static_app.zip
,获得static_app
文件夹 - 进入
static_app
文件夹, docker 进行打包docker build -t static-app-domain:v1 .
打包
- 运行
docker run -d -p 9001:80 --name static-app-domain-01 static-app-domain
运行
-
打开页面就可以看到了
打开浏览器
我购买的是腾讯云 ECS 服务器 活动优惠多多
网友评论