1. nginx 容器创建
docker run --name=nginx -p 80:80 -v /nginx/conf.d:/etc/nginx/conf.d -d nginx
运行这个命令会自动下载nginx容器并且运行。
2. 编辑nginx配置
cd /nginx/conf.d
vim xxxxx.conf
# 复制并粘贴下面的内容
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
3. docker start nginx
4. docker ps
成功后会显示:
[root@izm5ed10hr1jug0x6gutlbz conf.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8565816a63a nginx "nginx -g 'daemon ..." 21 minutes ago Up 14 seconds 0.0.0.0:80->80/tcp nginx
注:如果启动nginx出错,可以使用 docker logs -f -t --tail 10 nginx 来查看错误信息
5. 配置nginx 连接到你的jar包程序。
启动你自己的jar包
docker run --name xxxxx -p 8080:8080 -d mysite
编辑nginx配置文件为
server {
listen 80;
server_name xxx;
location / {
proxy_pass http://xxxxxx:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
6. 访问你的网站。默认为80 不需要加端口号