VPS Docker Deployment Using Nginx
Nginx Docker Setup on a VPS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
mkdir ~/dockerDemo/html && cd ~/dockerDemo;
echo 'hello world from docker using nginx' > html/index.html
touch Dockerfile docker-compose.yml nginx.conf
#nginx.conf
events {}
http {
server {
listen 80;
server_name sub.domain.com www.sub.domain.com>
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
}
#Dockerfile
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY html/ /usr/share/nginx/html/
#docker-compose.yml
services:
nginx:
build: .
ports:
- "80:80"
restart: always
#Build image and serve
docker compose build
docker compose up -d
#Verify the docker is serving the html site
#Checking Locally
curl localhost:80
# After pointing to the subdomain via cloudflare
curl http://sub.domain.com
This post is licensed under
CC BY 4.0
by the author.