nginx-hugo-blog-with-docker-hugo-nginx
## Docker
Docker Nginx 运行命令:
```bash docker run -d –name nginx -p 80:80 -p 443:443 -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/letsencrypt:/etc/letsencrypt -v /home/www/public:/home/www/public nginx:stable docker run –rm -it \ -v $(pwd):/src \ klakegg/hugo:0.95.0-ext-alpine ```
## Docker Compose
`docker-compose.yml`:
```yml version: '3.9'
services: nginx: image: nginx:stable volumes:
- '$PWD/nginx.conf:/etc/nginx/nginx.conf'
- './public:/usr/share/nginx/html/'
ports:
- '80:80'
blog: image: klakegg/hugo:0.95.0-ext-alpine volumes:
- '.:/src'
```
`nginx.conf`:
下面的 Nginx 配置用于运行 non-root Nginx
```nginx workerprocesses auto; workercpuaffinity auto;
pid /tmp/nginx.pid;
events { multiaccept on; workerconnections 1024; }
http { clientbodytemppath /tmp/clienttemp; proxytemppath /tmp/proxytemppath; fastcgitemppath /tmp/fastcgitemp; uwsgitemppath /tmp/uwsgitemp; scgitemppath /tmp/scgitemp;
charset utf-8; sendfile on; tcpnopush on; tcpnodelay on;
lognotfound off; typeshashmaxsize 4096; clientmaxbodysize 16M;
include mime.types; defaulttype application/octet-stream;
accesslog /var/log/nginx/access.log; errorlog /var/log/nginx/error.log warn;
include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } ```
## 搭配 Git Hooks
`$GITBAREREPO/.hooks/post-receive`(blog.git/hooks/post-receive):
```text #!/bin/bash git –work-tree=/home/www –git-dir=/home/git/blog.git checkout -f cd /home/git/docker-blog docker compose up -d ```
### 安装 Docker Compose v2
[在这里](/docs/tech/docker-compose-install)
参考资料
- [Nginx - Official Image | Docker Hub](https://hub.docker.com/_/nginx/)
- [nginxinc/docker-nginx: Official NGINX Dockerfiles](https://github.com/nginxinc/docker-nginx)
- [klakegg/hugo - Docker Image | Docker Hub](https://hub.docker.com/r/klakegg/hugo/)